Digital Logic Design · Problem type

Binary-coded decimal (BCD)

Use this for “Write 59 in BCD. How many bits does it take, and how many in plain binary?”

Chart

2⁷1282⁶642⁵322⁴162³82²42¹22⁰1001110113B
59 = 32 + 16 + 8 + 2 + 1: 111011₂, each column 2 times the one to its right.
By repeated ÷ 2: 59 → 29 r 1 → 14 r 1 → 7 r 0 → 3 r 1 → 1 r 1 → 0 r 1; the remainders read from the last are 111011.
In hex, the bits in fours: 0011 1011 = 3B₁₆.
This is an example. Type your own values to start a new problem.
N
Number
example
k
Decimal digits
worked out (not typed)
w
BCD bits
worked out (not typed)
D
BCD code
calculated
N₂
Binary
worked out (not typed)
b
Binary bits
worked out (not typed)

Formulas

k
=
⌊log₁₀
N
⌋
+
1
2 = ⌊log₁₀ 59⌋ + 1
w
=
4
×
k
8 = 4 × 2
D
=
N
+
6
×
⌊
N
10
⌋
+
96
×
⌊
N
100
⌋
+
1,536
×
⌊
N
1,000
⌋
0,101
1,001₂
=
59
+
6
×
⌊
59
10
⌋
+
96
×
⌊
59
100
⌋
+
1,536
×
⌊
59
1,000
⌋
b
=
⌊log₂
N
⌋
+
1
6 = ⌊log₂ 59⌋ + 1
N₂
=
N
11 1,011₂ = 59

Assumptions

•
BCD (8421 code) writes each decimal digit in its own 4 bits; 1010 to 1111 are never used.
•
N is a whole number from 1 to 9999, so its BCD code fits in 16 bits.
•
Plain binary writes the whole number in base 2, so it never needs more bits than BCD.

Step-by-step

WE KNOW
N = 59
FIND
decimal digits (k), BCD bits (w), BCD code (D), binary bits (b), binary (N₂)
Step 1 · Find decimal digits (k)
Use k = ⌊log₁₀ N⌋ + 1
A
number
from
10ᵏ⁻¹
up
to
10ᵏ
−
1
has
k
digits.
k
=
⌊log₁₀
59⌋
+
1
k
=
2
Step 2 · Find BCD bits (w)
Use w = 4 × k
Each decimal digit takes 4 bits.
w
=
4
×
2
w
=
8
Step 3 · Find BCD code (D)
Use D = N + 6 × ⌊N ÷ 10⌋ + 96 × ⌊N ÷ 100⌋ + 1,536 × ⌊N ÷ 1,000⌋
Write each decimal digit in 4 bits, side by side: read as one binary number, each digit then weighs a power of 16, not of 10.
D
=
59
+
6
×
⌊
59
10
⌋
+
96
×
⌊
59
100
⌋
+
1,536
×
⌊
59
1,000
⌋
5 = 0,101₂; 9 = 1,001₂
59 in BCD: 0,101 1,001
D
=
0101
1001₂
Step 4 · Find binary bits (b)
Use b = ⌊log₂ N⌋ + 1
A
number
from
2ᵇ⁻¹
up
to
2ᵇ
−
1
needs
b
bits.
b
=
⌊log₂
59⌋
+
1
⌊log₂
59⌋
=
5,
since
2
5
=
32
≤
59
<
64
=
2
6
b
=
6
Step 5 · Find binary (N₂)
Use N₂ = N
For comparison, the whole number in binary: divide by 2 again and again; read the remainders from the last.
N₂
=
59
59 ÷ 2 = 29 remainder 1
29 ÷ 2 = 14 remainder 1
14 ÷ 2 = 7 remainder 0
7 ÷ 2 = 3 remainder 1
3 ÷ 2 = 1 remainder 1
1 ÷ 2 = 0 remainder 1
59 = 111,011₂
N₂
=
11
1011₂
Check
Put the numbers back in. Both sides should match.
2 = ⌊log₁₀ 59⌋ + 1 ✓
8 = 4 × 2 ✓
0,101
1,001₂
=
59
+
6
×
⌊
59
10
⌋
+
96
×
⌊
59
100
⌋
+
1,536
×
⌊
59
1,000
⌋
✓
6 = ⌊log₂ 59⌋ + 1 ✓
11 1,011₂ = 59 ✓
Topic check
See what you know: 5 questions on this topic
New questions each time. Pass to mark it complete.

Related lessons

© 2026 SME. All rights reserved.