Binary Coded Decimals (BCD) Explained

Binary coded decimal (BCD) is a way to write decimal numbers in binary that's a little different to anything we've seen so far. In BCD we convert each digit in a decimal number to a 4-bit binary number in the usual way. BCD is often used in digital systems that plan on displaying these numbers later. It's much simpler to just pass every 4 digits of a BCD number to a separate character display and have it display that digit than it is to try to decode a large binary number every time we want to display it. BCD is less efficient for adding, subtracting, multiplying and dividing numbers so it's usually only useful when minimal to no processing of the numbers is required (displaying the current time on a digital clock face).
fact
To convert a decimal number to its binary coded decimal format convert each decimal digit to a 4-bit binary number.
example

Convert $$259_{10}$$ to BCD

So we convert each of the individual digits to a 4-bit binary code: \begin{align} 2\ \ \ \ \ \ \ \ 5\ \ \ \ \ \ \ \ 9\ \ \ & \\ 0010\ \ 0101\ \ 1001& \end{align} And we can read our answer straight off of this. $$259_{10} = 001001011001_2 \text{BCD}$$
fact
To convert from BCD back to decimal group the binary digits in groups of 4 (starting from the right), add leading 0s if necessary. Then convert each 4-bit group into its corresponding decimal digit, read the answer off the paper.
example

Convert $$11001000010_2$$ from BCD to decimal

We'll rewrite our binary number in groups of 4: $$0110\ \ 0100\ \ 0010$$ Where we've added the leading 0 to make up a complete 4-bit number on the left. Now convert each 4-bit group into its decimal equivalent: \begin{align} 0110\ \ 01&00\ \ 0010 \\ 6\quad\ \ 4& \quad\ \ 2 \\ \end{align} So $$11001000010_2 \text{BCD} = 642_{10}$$
fact
To add two BCD numbers:
1. Add them with normal binary addition
2. If the result of any 4-bit block of the answer (starting from the right) is greater than 9 or generates a carry bit at the end add 6
3. If after adding 6 to an invalid result, you get a carry bit, carry it into the next column as in a usual sum
Those rules are a little confusing so some examples will make things clearer.
example

Find $$0011 + 0100$$

Write out our problem in long form: \begin{align} 0011& \\ +\quad 0100& \\ \overline{\hphantom{+\quad 0100}}& \\ \end{align} Now we do a normal binary addition: \begin{align} 0011& \\ +\quad 0100& \\ \overline{\hphantom{+\quad 0100}}& \\ 0111& = 7 \\ \end{align} We only have one 4-bit result and its value is less than or equal to 9 so we're done. $$0011 + 0100 = 0111$$
example

Find $$00100011 + 00010101$$

\begin{align} 0010\quad 0011& \\ +\quad 0001\quad 0101& \\ \overline{\hphantom{+\quad 0001\quad 0101}}& \\ 0011\quad 1000 & \\ 3\quad\quad 8\hphantom{0\ }& \\ \end{align} Both of our 4-bit groups are less than or equal to 9 sp we're done and our answer is 38. $$00100011 + 00010101 = 00111000$$
Now let's try some examples that require us to handle those "bigger than 9" cases.
example

Find $$0111 + 0101$$

\begin{align} 0111& \\ +\quad 0101& \\ \overline{\hphantom{+\quad 0100}}& \\ 1100 & \\ \end{align} Now $$1100 \gt 1001 \text{(9)}$$ So we're going to add 6 ($$0110$$) which will skip over the invalid states and give us the valid BCD answer. \begin{align} 1100& \\ +\quad 0110& \\ \overline{\hphantom{+\quad 0100}}& \\ 10010 & \\ \end{align} Now we add padding 0s to our answer to fill out the 4-bit groups: \begin{align} 0001\ & \ 0010 \\ 1\phantom{00}\ & \phantom{00}2 \\ \end{align} So our answer is $$12_{10}$$
example

Find $$00010110 + 00010101$$

\begin{align} 0001\quad 0110& \\ +\quad 0001\quad 0101& \\ \overline{\hphantom{+\quad 0001\quad 0101}}& \\ 0010\quad 1011 & \\ \end{align} Now the right group is too large so we add 6: \begin{align} 0001\quad 0110& \\ +\quad 0001\quad 0101& \\ \overline{\hphantom{+\quad 0001\quad 0101}}& \\ 0010\quad 1011 & \\ +\quad 0110 & \\ \overline{\hphantom{+\quad 0001\quad 0101}}& \\ 0011\quad 0001 & \\ 3\ \ \quad\ \ 1\ \ & \\ \end{align} Our addition had a carry bit which we carried into the left group. Our final answer is then $$31_{10}$$
practice problems