Binary to BCD Converter

Convert an 8-bit unsigned binary number (0 to 255) into three BCD digits using the shift-and-add-3 (double dabble) algorithm: shift the binary number in one bit at a time, and before each shift add 3 to any BCD digit that is 5 or more. Input: bin, an 8-bit unsigned value. Output: bcd, 12 bits: bcd[11:8] hundreds, bcd[7:4] tens, bcd[3:0] ones. The output is declared reg so you can describe the algorithm in an always @* block with a for loop. The testbench applies all 256 inputs and compares every digit.

Compiler Output
Waveform Viewer