What Binary-Coded Decimal is
Binary-Coded Decimal (BCD) stores each decimal digit in its own 4-bit group called a nibble, using the standard 8-4-2-1 weighting. Rather than converting a whole number to pure binary, BCD keeps the decimal digits separate, which makes it easy to drive seven-segment displays and to perform exact decimal arithmetic in clocks, calculators, and financial hardware.
How it works
To encode, each decimal digit d (0–9) maps directly to its 4-bit binary
value. The number 2026 becomes four nibbles:
2 0 2 6
0010 0000 0010 0110
To decode, the input bits are split into groups of four from the right. Each
group is read with weights 8, 4, 2, 1 to recover one decimal digit. Any nibble
whose value lands between 1010 (10) and 1111 (15) is invalid BCD, because
those codes do not correspond to a single decimal digit, and the decoder reports
the error instead of guessing.
Tips and notes
When decoding, make sure the bit string length is a multiple of four; the tool
pads short groups on the left so you can spot a malformed input quickly. The
packed view shown here places two digits per byte, which is the most common
hardware layout. If you need unpacked BCD, simply prefix each nibble with a fill
nibble such as 0000 or 1111 depending on your platform’s convention.