Information Technology Reference
In-Depth Information
6
13
2
26
-26
0
2
13
-12
1
The second bit is 1; now divide 6 by 2. [10]
The first bit is 0; now divide 13 by 2. [0]
3
1
2
6
-6
0
2
3
-2
1
The third bit is 0; now divide 3 by 2. [010]
The fourth bit is 1; the leftmost bit is the division
result at the top, which is one. [11010]
Answer: 11010
Conversion Exampe C-16
Convert 26 to Binary
Alternative Method for Converting from Decimal to Binary
The dividing procedure just described works; it just takes a lot of time. Another way is to
remember the bit position values within a byte—128, 64, 32, 16, 8, 4, 2, 1—and play with
the bits until the sum adds up to the desired number. This method works when you con-
vert integer values between 0 and 255, inclusive. Table C-5 shows these binary numbers
and their decimal values.
Ta b l e C - 5
Bit Values
Binary Number
Decimal Value
10000000
128
01000000
64
00100000
32
00010000
16
00001000
8
00000100
4
00000010
2
00000001
1
For example, to conver t 26, you know that it is a number smaller than 128, 64, and 32, so
those 3 bits are 0 (000?????). Now you need to find a combination of 16, 8, 4, 2, and 1
that adds up to 26. This method involves using subtraction to compute the remaining
number. Start with the largest number, and make the bit at 16 a 1 (0001????). The differ-
 
Search WWH ::




Custom Search