I was explaining in a previous lesson that at the deepest level, computers store and process information only as two values, * 0* and

*. These values are the smallest individual pieces of information inside a computer, and they are called*

**1***. A bit can only contain a single value at a time, either a*

**bits***or a*

**0***. A group of eight bits is called a*

**1***, and sometimes, a*

**byte***. A byte is the smallest piece of memory that a computer can directly manipulate. It is also equal to a single character, or letter. So, when we type the letter*

**word***, we now know that it requires 1 byte, or 8 bits to be stored inside the memory.*

**A**The last aspect of this lesson is usually harder to grasp, specially by the beginners. However, this is not mandatory to be learned, you can still be great programmers even without knowing to directly count in binary.

If you remember from math lessons, binary counting, also known as * base 2 counting*, is counting using only two values,

*and*

**0***. According to the same principle, decimal counting, also known as*

**1***, is counting using 10 values, from*

**base 10 counting****to**

*0**. So, we can say that in the decimal system, we start from*

**9***and the upper limit is*

**0***, after which we need to add a new unit on a higher magnitude. Simillarly, in the binary system, we start counting from*

**9****and the upper limit is**

*0**, after which we also need to add a new unit on a higher magnitude. Binary counting is really the same as decimal counting, with the only difference of using only the first two numbers from it.*

**1**So, lets start counting in both binary and decimal system, for comparison. In both systems, we start with * 0*:

1 2 3 |
// decimal | binary //======================= 0 0 |

The next number is in both systems * 1*:

1 2 3 4 |
// decimal | binary //======================= 0 0 1 1 |

Here, the similarities end. In the decimal system, the number after * 1* is

*. However, since there is no value*

**2***in binary, because the system ends at*

**2***, we can consider that reaching*

**1***in binary (the last unitary number in binary) is the same as reaching*

**1***in decimal (the last unitary number in decimal). When we reach*

**9***in decimal, we add a unit on the next higher magnitude, and start couting the units from*

**9***again. In other words, in decimal, after*

**0***, we have*

**9***: a unit on the next higher manitude (tens) and starting again from*

**10****on the unitary digit. In binary it is the same: when we reach**

*0**, which is the last unitary number, we add*

**1****on the next higher magnitude and start again from**

*1**on the unitary place:*

**0**
1 2 3 4 5 |
// decimal | binary //======================= 0 0 1 1 2 10 |

We continue counting as usual: in decimal, the next number after * 2* is

*, in binary, after*

**3***we have*

**0***:*

**1**
1 2 3 4 5 6 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 |

Next, in decimal, its simple: after * 3* it comes

*. In binary, because on the units place we reached*

**4****, we need to start from**

*1**again, and add a unit on the next higher magnitude. But since we already have*

**0***on that place too, and since there is no*

**1***in binary, we add a unit on the next higher magnitude, the “hundreds” correspondent in decimal, and we also reset the “tens” equivalent to*

**2***:*

**0**
1 2 3 4 5 6 7 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 4 100 |

Then, in decimal, we know * 5* follows, while in binary, we start counting the units again:

1 2 3 4 5 6 7 8 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 4 100 5 101 |

Again, in decimal, next is * 6*, in binary we reached again to the point where units are

*, the last digit, so we need to reset them to*

**1****and add a unit on the next higher magnitude:**

*0*
1 2 3 4 5 6 7 8 9 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 4 100 5 101 6 110 |

We keep going as usual:

1 2 3 4 5 6 7 8 9 10 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 |

Now, again, in the decimal system, after * 7* we know that it follows

*. In binary, we reached the point where all three digits are the last number,*

**8***, as in decimal*

**1***is when all three digits are at the last possible number,*

**999***, and we need to reset them all to*

**9***and add a unit on the thousands place. It is the same in binary:*

**0**
1 2 3 4 5 6 7 8 9 10 11 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 |

And it goes like this forever, based on the same principles I described above:

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 |
// decimal | binary //======================= 0 0 1 1 2 10 3 11 4 100 5 101 6 110 7 111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111 16 10000 17 10001 18 10010 19 10011 20 10100 |

### Comments

Tags: binary, binary counting, bit, byte