# BCD Addition The **addition of binary-coded decimal** is similar to normal binary addition except that the result needs to be *corrected* to BCD if the binary value of any coded decimal digit *exceeds* $9$. This can be achieved by *adding* $6$ to any invalid BCD numbers. > [!Explanation]- > In binary-coded decimal, all decimal digits are encoded within *4 bits*. However, 4 bits are able to represent the numbers *0 to 15* in binary, which introduces 6 *invalid* BCD combinations. Thus, a 6 must be added to invalid BCD numbers to correct them. > $\begin{align} > 0000=0 &\quad 1000=8 \\ > 0001=1 &\quad 1001=9 \\ > 0010=2 &\quad 1010=\cancel{10} \\ > 0011=3 &\quad 1011=\cancel{11} \\ > 0100=4 &\quad 1100=\cancel{12} \\ > 0101=5 &\quad 1101=\cancel{13} \\ > 0110=6 &\quad 1110=\cancel{14} \\ > 0111=7 &\quad 1111=\cancel{15} \\ > \end{align}$ > [!Example]- > For example, adding $5$ and $7$ in BCD results in > $0101+0111=1100$ > Though $1100$ is the correct result in binary, it is an invalid BCD number. By adding $6$, the result is corrected into the BCD representation of $12$, the answer. > $1100+0110=0001\;0010$ For the result variable $Z$, the true BCD sum variable $S$, and the carry variable $C_{\text{out}}$: - If $Z\le 9$, then $S=Z$ and $C_{\text{out}}=0$. - If $Z>9$, then $S=Z+6$ and $C_{\text{out}}=1$ For example, adding $5$ and $7$ using BCD gives $1100$, which is an invalid BCD number and is just the binary equivalent $12$. By adding $6$ or $0110$ to the result, it becomes $0001\;0010$ which represents $12$ in BCD. ## Implementation To implement the BCD addition of one digit, a four-bit [[Adder#Full adder|adder]] is followed by logic which determines if adjustment is required and a two-bit adder for the adjustment. Note that if there is *carry out* in the four-bit adder or $Z_{3}$ and either $Z_{2}$ or $Z_{1}$ are on then $Z>9$. Additionally, adding $6$ or $0110$ to the result only affects the middle two bits $Z_{2}$ and $Z_{1}$. ![[BCDAdditionImplementation.svg]]