I have to convert a decimal number (1-255) to packed binary-coded decimal.
I have the idea of how it's supposed to work.
Example:
Convert 133 to BCD
1. Separate 133 to individual numbers (1, 3, 3).
2. Convert each number to binary (0001, 0011, 0011).
3. Print it in the form of "133 - 0001 0011 0011".
However, I'm struggling how to get the number separation and whatnot.
I'm just really confused how to program this.
Also, the decimal numbers have to be in 3 values, (eg; 4 has to be 004)
Because the result to BCD should be 0000 0000 0100, rather than just 0100.
If someone can help me with some C++ algorithm or snippet of code with some explanation, I would really appreciate it.