Page 323 - Embedded Microprocessor Systems Real World Design
P. 323
Original Number 1 0 0 1 1 0 1 0 0 1 0
Power of 2 210 29 28 27 26 25 24 23 22 21 20
Value of Bit 1024 512 256 128 64 32 16 8 4 2 1
So, our example binary number can be calculated as:
(0 x 1)+ (1 x 2)+ (0 x 4)+ (0 x 8)+ (1 x 16)+ (0 x 32)+ (1 x 64)+(1 x 128)
+ (0 x 256)+ (0 x512)+ (1 x 1024)
Or 2 + 16 + 64 + 128 + 1024, which is 123410.
Computers typically work with binary values that are 8, 16, 32, or 64 bits in length. Eight
bits can represent a value from zero to 255 (1 + 2 + 4 + 8 + 16 + 32 + 64 + 128). Sixteen
bits can represent a value from zero to 65,535. Thirtytwo bits can represent values up to
4.29 x lo9, and 64 bits can go up to 1.84 x 10”.
Obviously, writing numbers in binary is inconvenient for the human programmers who
must use the computer, so computer values are typically written in hexadecimal format. In
hexadecimal, usually abbreviated hex, the binary word is separated into 4bit groups. Our
example value looks like this when grouped that way:
10011010010 = 0100 1101 0010
The two numbers are the same, but spaces were added to the second number to separate
it into 4bit groups, like the way commas are sometimes added to decimal numbers. Note
that an extra zero was appended to the left of the leftmost group to make it a full 4 bits wide.
Now, remember what the value of each binary bit position was and you can calculate the
number this way:
10011010010=010011010010=
(0 x 1)+ (1 x 2)+(0 x 4)+ (0 x 8) = 2 =2 x 1
+(1~16)+(0~32)+(1~64)+(1~ =82=13~16
128)
+ (0 x 256)+ (0 x512)+(1 x 1024) = 1024 = 4 x 256
This is the same as what we had before, except that we’re finding the sum of each 4bit
group (2,82, and 1024) and then adding those sums together to get the total. So what about
the factors at the end of each line? Why is it important that 82 = 13 x 16? This is why:
2 = 2 x 1 = 2 x 16’
82 = 13 x 16 = 13 X 16’
4 x 256 = 4 x 16‘
So the word can be written: (4 x 16’) + (13 x 16l) + (2 x 16’)
As you can see, when we break the binary word into 4bit groups, each group is an increas-
ing power of 16 as you move from right to left. Each 4bit group represents a digit of a
base16 number. The 4bit groups make it base 16 because each 4bit group can represent a
maximum value of 15 (1 + 2 + 4 + 8). Including zero, this makes 16 possible values for each
digit. After 15, the number carries over to the next digit, just like decimal digits do when
you reach 9.
Now take another look at those 4bit groups. For the moment, we will treat each of these
4bit groups as individual binary numbers, and calculate them this way:
304 A@endZx B