I figured what better day than January 11th, 2011 (1/11/11) than to write this long overdue post on binary numbers.
Binary numbers are one of the fundamental things to computer science that need to be understood before moving onto the more complicated things. It’s a system of math and once it clicks, it will open up a lot of other things like understanding logic gates on up to and beyond the technical aspects of networking.
Your normal system of math is base 10 meaning you have ten different options for what a number might be: 0, 1, 2, 3, 4, 5, 6, 7, 8, or 9. The binary system is base 2 meaning you have two different options for a number: 0 or 1. It’s a lot like other boolean objects like true or false. What do you call a carbonated beverage: Pop or Soda? Which do you prefer Pepsi or Coke? (The correct answers are Pop and Pepsi, respectively.)
In the name of fun, Coca-Cola and Pepsi help us out by having their own flavors that fit nicely into this explanation: Coke Zero and Pepsi One. So, let’s learn (or review) the basics of Binary Systems using these flavors as pop; Coke Zero as zero and Pepsi One as one.
Terminology
Each can is a bit.
8 cans would be 8 bits.
8 bits also equal 1 byte.
Each can may either have the value of a…
One
or a zero.
Counting
Let’s count from 0 to 7 in binary. Then I’ll explain how it works.
0:
1:
2:
3:
4:
5:
6:
7:
Seven is the highest we can count to with only 3 bits. The formula for determining the highest value is to take 2^x -1, where x is the number of bits you have. In this case: 2^3 = 8. 8 -1 = 7.
Just like the base 10 number 453 is equal to 4*100 + 5*10 + 3*1, the same carries over to the binary system. In the binary number 7 above, it’s 1*4 + 1*2+ 1*1.
The value of the right-most bit, also known as the Least Significant Bit, is 2^0 multiplied by the one or zero that is there. 2^0 = 1, so:
2^0*0=0
2^0*1=1
The next bit to the left has the value of 2^1 or 2, so:
2^1*0=0
2^1*1=2
The third bit, in this case the Most Significant Bit, is 2^2 or 4, so:
2^2*0 = 0
2^2*1 = 4
So, the last example (7) is 4 + 2 + 1 = 7. The pattern continues so with 4 bits, the most significant bit would be equal to 2^3 or 8, and so on.
Here’s the value zero in decimal: 0 In binary: 00
In pop cans:
and here’s the value two in decimal: 2 In binary: 10
In pop cans:
Here’s a quick tip: If the Least Significant Bit (remember, the one all the way to the right) is a zero, the number is even. If the LSB is a 1, your number will be odd.
This continues on up to how many ever bits you have, from four bits…
on up to 11 bits and beyond.
Perhaps you’ve heard of 32-bit and 64-bit operating systems and now understand how a 64-bit OS has greater addressability over a 32-bit OS.
Decimal, Binary, and Beyond?
Decimal gives you a choice of 10 different numbers that can fill a place and binary gives you a choice of two. What if we introduced a third number to binary to make it trinary. A number’s place could either be zero, one, or two. (Perhaps we could use a Coke II for that role.) In that case, the same pattern would emerge:
To convert to decimal, the values would be:
3^0 * x =
3^1 * x =
3^2 * x =
and so on.
What if we made a number system that had more than ten possible digits? Well, there’s already a common one around called hexadecimal that uses 16 characters. In hexadecimal, there are 16 options for a space. It can either be: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, or F. You may recognize this as something you’ve seen before. Different computer codes use hexadecimal regularly like a network card’s MAC address or HTML color codes.
To convert to decimal, the values for hexadecimal would be:
16^0 * x=
16^1 * x=
16^2 *x=
and so on.
A hexadecimal digit can also be thought of a four bit binary digit. For example, this 1010 in binary would equal A (or 10 in decimal):
Ahh… It’s good to be done with that post. After reading through it, review the post to see if you understand the way binary numbers are counted or added together. There are plenty of great resources on the web or YouTube if you would like to continue learning.
That’s just the basics of binary and I hope I kept it accurate. Writing it up took a while but finally completed a thought I had at least two years ago. And as a reward for you, you should now understand the punchline of this joke:
“There are only 10 kinds of people in the world. Those who understand binary and those who don’t.”