|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
Integers: BCD |
|
|
|
|
Since people think in
decimal, it may be convenient to use a decimal-like representation. |
|
Binary coded decimal
(BCD) uses unsigned binary to represent each decimal digit. |
|
|
How many bits are needed? |
|
|
|
|
4 bits per decimal digit:
ceil (lg 10) = 4 |
|
|
Since 4 bits can
represent 16 values, 6 values are unused for every digit. |
|
|
Advantages |
|
|
|
|
Decimal input/output
doesn't require complicated conversion. |
|
|
|
Fewer problems with
repeating fractions. |
|
|
|
Example: |
|
|
|
|
|
Represent 1739ten in BCD: |
|
|
|
|
decimal |
1 |
7 |
3 |
9 |
|
|
|
|
BCD |
0001 |
0111 |
0011 |
1001 |
|
|
|
Some early computers
used BCD representation, and many calculators still use BCD. |
|
Since calculators can be
much slower than computers, they can use hardware which |
|
|
operates on 4 bits at a
time. |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|