Binary-coded Decimal - Addition With BCD

Addition With BCD

It is possible to perform addition in BCD by first adding in binary, and then converting to BCD afterwards. Conversion of the simple sum of two digits can be done by adding 6 (that is, 16 – 10) when the five-bit result of adding a pair of digits has a value greater than 9. For example:

1001 + 1000 = 10001 9 + 8 = 17

Note that 10001 is the binary, not decimal, representation of the desired result. In BCD as in decimal, there cannot exist a value greater than 9 (1001) per digit. To correct this, 6 (0110) is added to that sum and then the result is treated as two nibbles:

10001 + 0110 = 00010111 => 0001 0111 17 + 6 = 23 1 7

The two nibbles of the result, 0001 and 0111, correspond to the digits "1" and "7". This yields "17" in BCD, which is the correct result.

This technique can be extended to adding multiple digits by adding in groups from right to left, propagating the second digit as a carry, always comparing the 5-bit result of each digit-pair sum to 9.

Read more about this topic:  Binary-coded Decimal

Famous quotes containing the word addition:

    The most important American addition to the World Experience was the simple surprising fact of America. We have helped prepare mankind for all its later surprises.
    Daniel J. Boorstin (b. 1914)