When we need to process information about money, eg
business accounts, economic simulations, etc, many packages and compilers have
the option of storing and processing the numbers in a very accurate form called
BCD. In it’s simplest form this involves the conversion of each digit in turn
into binary equivalent so there is no lack of accuracy with very large numbers.
All we do is add more bytes to get the accuracy. eg
Thus there are several “illegal” codes - those between 10
and 15 since these should have been separated into two individual codes. eg
1010, 1011, 1100, 1101, 1110, 1111
This is fortunate since, if an illegal code is detected
after an arithmetic operation, it can be easily detected and corrected. The
other advantage of BCD is that 2 BCD codes can be stored in one 8 bit location.
If ASCII codes (see later) were to be used then only one per location would be
possible.
One of the problems with packing two BCD codes into one
byte is how to extract (or unpack) them for processing. The full explanation
for this is shown in the notes on logical operations.
BCD Addition
Two possible situations can occur when straightforward
BCD addition is employed:-
legal BCD codes produced
or illegal BCD codes produced
No comments:
Post a Comment