I felt like doing a quick post on something this evening, and so tonight I’ll be teaching you how to count in binary. Regardless of whether or not you are a programmer, being able to count in binary is quite fun.
What is Binary?
Binary refers to a system consisting of two components, and in the realm of computing we recognize these two as ones and zeroes.
1 .. 2 .. 4 ?
Counting in binary is quite simple. Consider a block of zeroes, say 8 (eg. 00000000), each of these numbers are called bits, and 8 bits make up one byte.
0 00000000 1 00000001 2 00000010 4 00000100
Notice the pattern here, that each time you move the 1 one over toward the left, you increase the value by a factor of 2 (multiplication by 2). So, 8 would be 00001000.
Where did 3, 5, 6 and 7 go ?
0 00000000 1 00000001 2 00000010 3 00000011 4 00000100 5 00000101 6 00000110 7 00000111 8 00001000
Notice that on each pass of multiplication by 2 (1, 2, 4, 8, 16), we fill the gap of zeroes behind it in a pattern similar to how we did the multiplication. The only difference is that we are counting on top of it. If you look away from the bit that make up the number 8 (fifth bit from the left), you are just counting 1, 2, 3, etc. all over again — this is illustrated below.
8 00001000 9 00001001 10 00001010 11 00001011 12 00001100 13 00001101 14 00001110 15 00001111 16 00010000
There is also a visual pattern going on here, if you look at each column of the numbers 0 through 8, look at the rightmost column, and you will see the alternating pattern of even and odd numbers (0 is even, while 1 is an odd number). The same pattern emerges when you look at the next column, which alternates in a pattern of 2/2 (2 zeroes, 2 ones, etc.). As you may have guessed, these patterns are found all throughout the columns, as the next column will then be 4/4 — this makes a nice rule of thumb to remember binary counting by, you can also immediately tell whether or not it is an odd or even number, just by looking at the rightmost column.
If this still doesn’t make a whole lot of sense, try adding two binary numbers together, as shown below (overly simplified, for illustrating the correlation).
8 + 2 = 10 00001000 + 00000010 = 00001010 16 + 5 = 21 00010000 + 00000101 = 00010101
Hopefully this was understandable. It is quite easy to count in binary, once you know the pattern. With 8 bits (one byte), you can count from 0 to 255, of course you can always extend the range to 16, 32 or even more bits if you wish. Knock yourselves out, have fun.