Encode and decode Binary Coded Decimal (BCD) from the command line. Zero dependencies.
npm install -g @kszongic/bcd-cli# Encode decimal to BCD
bcd encode 1234
# BCD binary: 0001 0010 0011 0100
# BCD hex: 0x1234
# BCD bytes: 12 34
bcd encode 9876
# BCD binary: 1001 1000 0111 0110
# BCD hex: 0x9876
# BCD bytes: 98 76
# Decode BCD hex to decimal
bcd decode 0x1234
# 1234
bcd decode 98 76
# 9876
# Pipe from stdin
echo "42" | bcd encode
# Shorthand: just pass a number
bcd 42Binary Coded Decimal encodes each decimal digit in 4 bits (a nibble). It's widely used in financial systems, embedded devices, and legacy protocols where exact decimal representation matters.
| Digit | BCD |
|---|---|
| 0 | 0000 |
| 1 | 0001 |
| 2 | 0010 |
| ... | ... |
| 9 | 1001 |
MIT © 2026 kszongic