Digital Signal Processing Reference
In-Depth Information
Table 10.3: Converting from decimal to binary.
number
number / 2
remainder
38
19
0
19
9
1
9
4
1
4
2
0
2
1
0
1
0
1
the remainders (which must be either 0 or 1). Repeat this until we get zero for the
result. Then we write these remainders from the bottom to the top.
For example, suppose we want to convert the number 38 to binary. As we can
see from Table 10.3, the remainders (in reverse order) are 100110. Since we have
not established how many bits we use in storing the xed-point binary number,
and because the left-most bit typically indicates sign, we append a zero to the left
to avoid confusion. This gives us 0100110 as our answer. We can check this by
converting it back to decimal: 32 + 4 + 2 = 38.
This assumes that the decimal number is positive. When it is negative, use the
absolute value instead. At the end, convert all 0s to 1s and all 1s to 0s, then add 1.
Keep in mind that 1 + 1 = 10 in binary. This nal step (called two's complement)
returns the correct bit pattern for negative numbers. We will not worry about
negative numbers below, since the oating-point standard uses a sign bit instead of
using two's complement.
But what if we wanted to convert 38.1 to a xed-point binary representation? We
already know the bits to the left of the radix point, and we use a similar algorithm
to nd the fractional part.
We will start with the fractional number, multiply by 2 (or, if you prefer to think
of it this way, divide by 2
1 ), and keep track of the whole part. We repeat this with
the fractional part of the previous number until we get a zero for the fractional part.
Notice that in Table 10.4 the last fractional number, 0.4, was already seen in the
table. This fractional part does not have a compact binary representation. Instead,
like the number 1/3 in decimal, it repeats forever. The best we can do is store an
approximation of :00011.
Using these two decimal-to-binary techniques together, we conclude that 38.1
Search WWH ::




Custom Search