The TCP/IP Guide - Version 3.0 (Contents) ` 124 _ © 2001-2005 Charles M. Kozierok. All Rights Reserved.
A lot of people are intimidated by binary numbers, because at first they seem quite
confusing. The key to understanding them is realizing that they are exactly the same as
decimal numbers, except that instead of each digit having a value in the range of 0 to 9,
each has a value in the range of 0 to 1. For example, when you count in decimal, you go up
to 9 in the one’s place, and then you need a second place for “tens”. If you go above 99,
you need a third place for “hundreds”. Each additional place added on the left is a higher
power of ten. Binary is the same, except the limit for each place is 1 instead of 9. In binary,
you go up to 1 in the one’s place, and then need a second place for “twos”. If you go above
3, you need a third place for “fours”. Each added place is a subsequent higher power of two,
rather than ten.
Thus, where counting in decimal goes 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13 and so on,
counting in binary goes 0, 1, 10, 11, 100, 101, 110, 111, 1000, 1001, 1010, 1011, 1100,
1101. The concept is identical—you just need a lot more digits for binary numbers because
there are so many fewer values allowed for each digit. For example, the number “13” in
decimal is the same as “1101” in binary. How? Well, in decimal, we have a 3 in the one’s
place, plus a “1” in the “tens” place, which has a value of 10. This is 3+10=13. In binary, we
have a “1” in the “ones” place, plus a “1” in the “fours” place, plus a “1” in the “eights” place,
which is 1+4+8 or 13.
To take a more complex example, 211 in decimal is 11010011 in binary. Table 3 shows how
the two are equivalent, by adding the values for each binary digit place where there is a 1.
Read it from left to right, going top to bottom. Starting in the left-most column, we see that
the example number has a 1 in the "128s" place. So we start with a sum of 128. In the next
column there is a 1 in the "64s" place, so we add 64 for a running sum of 192. But in the
"32s" place the binary digit value is 0, so we don't add 32 to the sum. We continue down to
the "ones" place to get the decimal equivalent of the binary number.
As you can see from this, a binary number with N digits can hold up to 2
N
values. So, a
byte, with eight bits, can hold 2
8
or 256 different values, which are numbered from 0 to 255.
A 16-bit word can hold 2
16
or 65,536 values.
Making Binary Numbers Easier to Use By Grouping Bits
One problem with binary numbers is that while computers love them, they are unintuitive for
humans, who are used to decimal numbers. One reason for this is that they quickly get very,
very long and cumbersome to deal with. For example, 1,000,000 in decimal is
Table 3: Binary and Decimal Number Equivalents
Binary Number 11010011
Power of Two
2
7
2
6
2
5
2
4
2
3
2
2
2
1
2
0
Value of Digit Place 1286432168421
Value For This
Number
128 64 0 16 0 0 2 1
Running Sum (from
left to right)
128
128+64
= 192
192
192+16
= 208
208 208
208+2 =
210
210+1 =
211