Using Binary Numbers

 

To understand binary (base two) numbers, it's best to first understand the decimal (base ten) numbers that we use in everyday life. There are ten possible digits in the base 10 system, numbers 0-9. The smallest place value for a number is one, and as you read from right to left in a number, the value of each place is ten times more than the last. (This is more complicated to say than to do - you've been doing this unconsciously since you have been quite young.)

 

The decimal number 714, for example, is actually

7(100) + 1(10) + 4(1) =

700 +10 +4 =

714

 

Here are some other examples:

 

The decimal number 1984 is:

1(1000) + 9(100) + 8(10) + 4(1) = or 1(103) + 9(102) + 8(101) + 4(100) =

1000 + 900 +80 + 4 =

1984

 

The decimal number 2003 is:

2(1000) + 0(100) + 0(10) + 3(1) = or 2(103) + 0(102) + 0(101) + 3(100) =

2000 + 0 + 0 +3 =

2003

 

Binary numbers work in the same general manner, except that base two has only two numbers (0 and 1) that are called bits (binary digits). Also, the place values double, instead of multiplying by ten, as you move from right to left. So, instead of 1's, 10's, 100's, 1000's, etc., we have binary place values of 1's, 2's, 4's, 8's, 16's, etc.

 

The binary number 1011 is thus equivalent to:

1(8) + 0(4) + 1(2) + 1(1) or 1(23) + 0(22) + 1(21) + 1(20)

8 + 0 + 2 + 1 =

11

 

For another example, take the binary number 100111:

1(25) +0(24) + 0(23) + 1(22) + 1(21) + 1(20) =

1(32) +0(16) + 0(8) + 1(4) + 1(2) + 1(1) =

32 + 4 + 2 + 1 =

39

 

Here is what counting in binary looks like, with the decimal equivalents:

0                    0000

1                    0001

2                    0010

3                    0011

4                    0100

5                    0101

6                    0110

7                    0111

8                    1000

9                    1001

10                1010

11                1011

12                1100

13                1101

14                1110

15                1111

 

Do you see the pattern here? Look at the 1's column at the far right - do you see the alternating 0's and 1's as you go down the column? Then look at the two's column, the one next to the left. Now the pattern is a repeating 0011. If you go one more to the left, to the 4's column, the repeating pattern becomes 00001111. The 8's column is then not surprisingly 0000000011111111. No matter how high you decide to count in the binary system, you will see these repetitive patterns. Every binary place (column) to the left will have a run of 0's that is twice as big as the one to its right.

 

Converting from a decimal to binary number is not difficult - all you have to do is write out the possible binary place values lower than the number you are converting, and then see which ones are needed by subtracting. For example, take the number 39 that we just used above. That number in binary will be:

?(32) + ?(16) + ?(8) + ?(4) + ?(2) + ?(1), where the "?" will be either a 0 or a 1. We didn't go higher than 32 because there obviously aren't any 64's in the number 39.

 

There is a 32 in 39, with 7 left over, so we have 1xxxxx so far

There isn't a 16 in 7, so we have 10xxxx so far

There isn't an 8 in 7, so we have 100xxx so far

There is a 4 in 7, with 3 left over, so we have 1001xx so far

There is a 2 in 3, with 1 left over, so we have 10011x so far

There is a 1 in 1, so we finally have 100111

 

Here is a similar example with the decimal number 86:

?(64) +?(32) + ?(16) +?(8) + ?(4) + ?(2) + ?(1)

(There was no need to go higher than 64, because there are no 128's in 88.)

There is a 64 in 88, with 22 left over, so we have 1xxxxxx so far

There isn't a 32 in 22, so we have 10xxxxx so far

There is a 16 in 22, with 6 left over, so we have 101xxxx so far

There isn't an 8 in 6, so we have 1010xxx so far

There is a 4 in 6, with 2 left over, so we have 10101xx so far

There is a 2 in 2, with 0 left over, so we have 101011x so far

There isn't a 1 in 0, so we finally have 1010110

 

To check, 1(64) + 0(32) + 1(16) +0(8) + 1(4) + 1(2) + 0(1) =

64 + 16 +4 +2 +

86

 

The largest binary number you will typically deal with is 11111111, or 255, the largest number possible in an 8-bit byte. This is why image-processing programs such as Photoshop, for example, provide you will color intensity levels ranging from 0 (binary all 0's) to 255 (binary all 1's).

 

Sometimes, this "all 1's in a byte is 255" knowledge can avoid a lot of additions. For example, take the binary number 11011111. To convert, you could do a whole lot of additions, or you could take the short cut by realizing that there isn't anything in the 32's place. The binary number is thus 255-32, or 223. If this method confuses you, stick with the addition method.

For practice, simply pick any number you like and convert it in both directions. If you come back to your original starting number, you're correct!