Information Technology Reference
In-Depth Information
Converting Binary to Decimal
To c o n v e r t a b i n a r y n u m b e r t o d e c i m a l , m u l t i p l y e a c h i n s t a n c e o f 0 o r 1 b y t h e p o w e r o f 2
associated with the position of the bit in the binary number. The first bit, starting from
the right, is associated with 2 0 = 1. The value of the exponent increases by 1 as each bit is
processed, working leftward. As shown in Table C-4, each bit in the binary number
10101010 has a decimal equivalent from 0 to 128 based on the value of the bit multiplied
by a power of 2 associated with the bit position. This is similar to decimal numbers, in
which the numbers are based on powers of 10: 1s, 10s, 100s, and so on. In decimal, the
number 111 is (1*100) + (1*10) + (1*1). In binary, the number 11111111 is the sum of (1*2 7 )
+ (1*2 6 ) + (1*2 5 ) + (1*2 4 ) + (1*2 3 ) + (1*2 2 ) + (1*2 1 ) + (1*2 0 ) = 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 =
255. For 10101010, the result is 128 + 0 + 32 + 0 + 8 + 0 + 2 + 0 = 170. Examples follow.
Ta b l e C - 4
Decimal Values of Bits in a Binary Number
Power of 2
2 7 = 128
2 6 = 64
2 5 = 32
2 3 = 8
2 2 = 4
2 0 = 1
Binary
1
1
1
1
1
1
Note: Just memorize 1, 2, 4, 8, 16, 32, 64, and 128. Use it as you read a binary number
from right to left. This technique should be helpful in fast conversions.
Sum: 128 + 0 + 32 + 16 + 0 + 4 + 2 + 1
Answer = 183
Conversion Example C-13
Convert 10110111 to Decimal
Sum: 16 + 8 + 0 + 2 + 1
Answer = 27
Conversion Example C-14
Convert 00011011 to Decimal
Sum: 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1
Answer = 255
Conversion Example C-15
Convert 11111111 to Decimal
Converting Decimal to Binary Numbers
This procedure is similar to converting from hex to decimal (by dividing), but now you di-
vide the decimal number by 2. You use each residual to build the binary number by
prepending each residual bit to the previous bit, starting on the right. Repeat the proce-
dure until you cannot divide anymore. The only problem is that for large numbers, you
might have to divide many times. You can reduce the number of divisions by first convert-
ing the decimal value to a hexadecimal value and then converting the intermediate result
to the binary representation. After the following example, you will read about an alternate
a single octet.
 
Search WWH ::




Custom Search