Closed Form Addition of BCD numbers

93 Views Asked by At

Binary Coded Decimal (BCD) number representation is a 4-bit encoding which maps numbers 0-9 to their counterpart binary codes. Addition of BCD numbers can be formulated as follows:

  • z = a + b (If z < 10)
  • z = a + b - 10 (If z >= 10)

For instance, If we add 7 (0111) and 8 (1000), we get 15-10=5, and a carry for a higher order. My question: How can we formulate the aforementioned formula without comparison operator; i.e. what is a closed form formula for addition of 2 BCD numbers (like for example z = a+b-3ab+64a^2-128b^3, this is just an example form of what I need)?

Thanks

1

There are 1 best solutions below

3
On

It will be an enormous expression but you can do it. If we note that $z=7$ when $a=4$ and $b=3$ we can have a term on the right that is $a(a-1)(a-2)(a-3)(a-5)\ldots (a-9)b(b-1)(b-2)(b-4)\ldots (b-9)$ divided by a constant. The point is that this term is $0$ unless $a=4,b=3$ and we choose the constant to make the product $7$ when $a=4,b=3$. Another $99$ terms will get the job done. If you write it out, you can feed it to a computer algebra package to expand and collect terms for you.