
Number Systems 7
We can look for the highest power of two that is not greater than the
decimal number, place a 1 in the equivalent bit position, and then sub
tract this value from the decimal number. We repeat this operation until
the number is zero. Bit positions not used in this subtractive process are
set to 0. For example, we can convert 5710 (57 in base 10) to binary by
the following steps:
57 - 25 = 25
25 - 24 = 9
9 - 23 = 1
1 - 2® = 0 (finished)
This gives us the binary number
l(2)5+l(2)4+l(2)3+0(2)2+0(2)1+l(2)° = 1110012
Another method can also be used. We can divide the original decimal
number by two and check the remainder. If the remainder is one, a binary
one is generated. We repeat this division by two until we obtain a zero.
This method gives us the bits in reverse. In other words, we get 2°, 21,
and so on. For example, using the same number as above:
57/2 = 28 R 1
28/2 = 14 R 0
14/2 = 7 R 0
7/2 = 3 R 1
3/2 ■ 1 R 1
1/2 = 0 R 1 (finished)
Reading the bits in reverse gives us 1110012, which is the same number
as we arrived at before. The method you use is up to you.
These methods can be used to convert from any number base to any
other number base. However, the arithmetic must be done in the number
base of the number being converted. As this becomes complicated when
converting from a system other than decimal, you are better off to convert
the number to decimal and then the decimal number to the new base.
There are a few exceptions to this rule. One of these exceptions is the
conversion of the hexadecimal (hex) base to or from binary. Since hex is
used quite extensively with the 68000 family, it is the topic of our next
discussion.
Komentáře k této Příručce