Skip to content

Digital systems, number bases, and conversions

A digital system counts, stores, and processes quantities. Outside the machine we use decimal (base 10). Inside, almost everything is binary (base 2): each digit is 0 or 1. Octal (base 8) and hexadecimal (base 16) are shortcuts so you do not write endless strings of ones and zeros.

This unit is the first-partial foundation: if conversions have no method, codes, Hamming, and BCD on displays all fall apart.

A positional system gives each digit a weight: a power of the base, counting from the right (position 0).

N = dn · bn + ⋯ + d1 · b1 + d0 · b0
SystemBaseDigitsExample
Decimal100–945₁₀
Binary20, 1101101₂
Octal80–755₈
Hexadecimal160–9 and A–F (10–15)2D₁₆

MSB and LSB (most and least significant bit)

Section titled “MSB and LSB (most and least significant bit)”

The acronyms show up on exams and datasheets; keep the literal meaning:

AcronymEnglishMeaningWhere it sitsWeight
MSBMost Significant Bitthe bit that counts the mostleft endthe largest (in 8 bits: 128)
LSBLeast Significant Bitthe bit that counts the leastright endthe smallest (always 1)

“Significant” here is not “important in the sentence”: it is how much the bit adds to the value. Flip the LSB and the number changes by 1. Flip the MSB of a byte and it changes by 128.

Example 101101₂ (6 bits):

position 543210
bit 101101
weight 32168421
MSB LSB

The MSB is the left 1 (worth 32). The LSB is the right 1 (worth 1). In a byte, bits are numbered 7…0: bit 7 = MSB, bit 0 = LSB.

Nibble, byte, and the hex ↔ binary table

Section titled “Nibble, byte, and the hex ↔ binary table”

A bit is 0 or 1. A nibble is a group of 4 bits. A byte is 8 bits = two nibbles.

Four bits give 2⁴ = 16 patterns: 0000 through 1111. Hexadecimal uses exactly those 16: one hex digit is one nibble. That is why 2D₁₆ is two nibbles: 0010 and 1101.

That is written as an equivalence table (below). It looks like a truth table because it lists every 4-bit combination; the last column means something else.

HexBinary (nibble)Decimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115

Octal is the same with 3 bits (8 combinations): 0 → 0007 → 111.

Binary is the hub: almost every conversion goes through it. Arrows are two-way. Decimal ↔ binary is direct. Hex ↔ binary and octal ↔ binary are too (bit groups). Decimal ↔ hex is not grouping: go through binary, or divide by 16.

Decimal 10
Octal 8
Binary 2
Hex 16
Decimal ↔ hex is not grouping: go Decimal → Binary → Hex (or ÷16).

There are two methods that give the same result. On the exam either is fine if you show the work.

Method 1 — sum of weights. Write the power of 2 under each bit (… 32 16 8 4 2 1) and add only where the bit is 1.

Example 101101₂:

position 543210
bit 101101
weight 32168421
adds 32841
MSB LSB

sum: 32 + 8 + 4 + 1 = 4510

Zeros add nothing (cells with —). In green: 32 + 8 + 4 + 1 = 45₁₀.

Method 2 — double and add (from the MSB). Take the first bit (left). Then, for each bit after that: (what you have) × 2 + that bit. Writing the 2 on every line is fine; repeating the running total is the point.

101101₂, left to right:

Incoming bitOperationResult
1 (MSB)start with that bit1
01 × 2 + 02
12 × 2 + 15
15 × 2 + 111
011 × 2 + 022
1 (LSB)22 × 2 + 145

Again 45₁₀.

William George Horner (19th century) described a way to evaluate a polynomial by nesting adds and multiplies, without computing each power on its own.

A base-b number is a polynomial: the leftmost digit multiplies bⁿ, the next bⁿ⁻¹, and the LSB multiplies b⁰ = 1. That factors as:

101101₂ = (((((1)×2 + 0)×2 + 1)×2 + 1)×2 + 0)×2 + 1

Each pair of parentheses is one row of the table: running total × 2 + bit. That is why “double and add” and “Horner’s rule” are the same method when the base is 2.

In hexadecimal it would be × 16 + digit; in decimal, × 10 + digit. You do not need to memorize 32, 64, 128…: the nesting produces them.

Useful when the number is long. With 6–8 bits, the weight sum is still easier to see.

Divide by 2, write the remainder (0 or 1). Read binary bottom to top (last remainder is the MSB).

45₁₀:

45 ÷ 2 = 22 remainder 1
22 ÷ 2 = 11 remainder 0
11 ÷ 2 = 5 remainder 1
5 ÷ 2 = 2 remainder 1
2 ÷ 2 = 1 remainder 0
1 ÷ 2 = 0 remainder 1

101101₂ (check: 32+8+4+1 = 45).

From the LSB, group 3 bits. Pad with zeros on the left if needed. Each group is one octal digit.

101101₂101 10155₈

The other way: each octal digit → 3 bits. 153₈001 101 0111101011₂.

Same idea, 4 bits at a time.

101101₂0010 11012D₁₆

2F₁₆0010 1111101111₂ = 32+8+4+2+1 = 47₁₀.

On the map there is no grouping arrow between decimal and hex: 10 and 16 do not split the same bit width. The classroom path (and the safest on the exam) is through the hub:

decimal → binary → hex and back hex → binary → decimal

Out (45₁₀ → hex), via binary:

  1. Decimal → binary (÷ 2): 45₁₀ = 101101₂ (already done above).
  2. Binary → hex (groups of 4 from the LSB). Six bits left: pad zeros on the left → 0010 1101.
  3. Each nibble is a hex digit: 0010 = 2, 1101 = D2D₁₆.

Back (2D₁₆ → decimal), via binary:

  1. Each hex digit → 4 bits: 2 = 0010, D = 110100101101₂.
  2. Binary → decimal (weights): 32+8+4+1 = 45₁₀.

Another path (no bit groups): divide the decimal by 16, remainders bottom to top (10=A … 15=F). That is not a “direct grouping” on the map: it is different arithmetic, same landing.

45 ÷ 16 = 2 remainder 13 → D
2 ÷ 16 = 0 remainder 2 → 2

Read remainders bottom to top: 2D₁₆. Back: 2×16 + 13 = 45.

Split the number into integer and fraction (the point). Convert the integer with the methods above. The fraction is not divided by 2: you multiply by the base.

Rule: fraction × 2. The integer that appears (0 or 1) is the next bit after the point. Keep only the new fractional part and repeat. The first bit you get is the heaviest one to the right of the point (2⁻¹ = 1/2).

Stop when the fraction is 0, or after n bits if they ask (if it never hits 0, you approximate).

Example 0.625₁₀:

StepCalculationBit outFraction left
10.625 × 2 = 1.25010.250
20.250 × 2 = 0.50000.500
30.500 × 2 = 1.00010 (done)

Read bits top to bottom (first bit is closest to the point): 0.101₂.

Mixed number: convert each side and join at the point. 5.625₁₀5 = 101₂ and 0.625 = 0.101₂101.101₂.

If it never hits 0 (as with 0.1₁₀), binary repeats. Write as many bits as they ask; that is not a method error.

To the right of the point the weights are 1/2, 1/4, 1/8, 1/16… (or 0.5, 0.25, 0.125…). Add only where the bit is 1. Same as integers, but going right.

0.101₂:

BitWeightAdds
1 (next to the point)0.50.5
00.25
10.1250.125

0.5 + 0.125 = 0.625₁₀. With the integer part: 101.101₂ = 5 + 0.625 = 5.625₁₀.

Same idea, different base: fraction × 8 (octal) or × 16 (hex). The integer that pops out is the next digit (in hex, 10–15 = A–F).

The hub map still helps: decimal fraction → binary → hex (groups of 4 bits to the right of the point; pad zeros on the right if needed).

In the same chapter 2, after converting, you get BCD, excess-3, Gray, and parity (parity is finished in Hamming).

BCD (Binary-Coded Decimal): each decimal digit is translated on its own, with 4 bits, using the 0–9 nibble table. You do not convert the whole number to binary and then slice it.

Table you use (0–9 only; 10101111 are not BCD digits):

DigitBCD (4 bits)DigitBCD
0000050101
1000160110
2001070111
3001181000
4010091001

45₁₀ in BCD, digit by digit:

  1. The 4 → table → 0100
  2. The 50101
  3. Glue them: 0100 0101

Straight binary of 45 is a different sum: 32+8+4+1 = 101101₂. If you group that 101101 by fours (0010 1101) you get hex 2D, not BCD. That is why the two columns disagree and both are still correct.

59₁₀ in BCD: 50101, 910010101 1001.
Straight binary: 32+16+8+2+1 = 111011₂ (again different).

Exams show 00–99 switches (4 bits for tens + 4 for units) and displays. “Write 59 in BCD” is not “write 59 in binary”.

Add 3 to each decimal digit, then write 4 bits: 0 → 0011, 9 → 1100.
59₁₀ in excess-3: 5+3=8 → 1000, 9+3=12 → 11001000 1100.

It shows up in BCD arithmetic (74LS83 later). Here you only need to build it digit by digit.

Gray code (reflected binary) is built so that going to the next number flips only one bit. In ordinary binary, 7 → 8 is 01111000: four bits change at once; a mechanical encoder can read garbage in between. Gray avoids that. It is not for arithmetic: there are no 1, 2, 4, 8 weights.

From 0 to 7 (each row differs from the previous by one bit):

DecimalBinaryGray
0000000
1001001
2010011
3011010
4100110
5101111
6110101
7111100

Copy the MSB. Each next Gray bit is the XOR of that binary bit and the binary bit to its left. XOR is 1 when the two bits differ.

G_MSB = B_MSB
G = (binary bit on the left) XOR (binary bit in this position)

Example 1011₂ → Gray:

MSBLSB
Binary1011
Gray1 (copy)1 XOR 0 = 10 XOR 1 = 11 XOR 1 = 0

Gray = 1110.

Another: 101101₂ (45 from earlier) → copy the leading 1; then XOR along: 1⊕0=1, 0⊕1=1, 1⊕1=0, 1⊕0=1, 0⊕1=1111011.

Copy the MSB. Each next binary bit is XOR of the binary you already have (left) with Gray in this position.

B_MSB = G_MSB
B = (binary already found on the left) XOR (Gray in this position)

1110 Gray → 1, 1⊕1=0, 0⊕1=1, 1⊕0=11011₂ (the original).

Exercises (different numbers from the worked example)

Section titled “Exercises (different numbers from the worked example)”

Do them on paper; the method must survive a number change.

  1. Convert 53₁₀ to binary, octal, and hexadecimal.
  2. Convert 1101110₂ to decimal, octal, and hex.
  3. Convert 3A₁₆ to binary and decimal.
  4. Write 86₁₀ in straight binary and in BCD. How do they differ?
  5. Write 86₁₀ in excess-3.
  6. 0.375₁₀ to fractional binary.
  7. Convert 10110₂ to Gray and check Gray → binary.

Quick checks: (1) 53 = 110101₂ = 65₈ = 35₁₆. (2) 110 = 156₈ = 6E₁₆. (3) 0011 1010₂ = 58. (4) binary 1010110, BCD 1000 0110. (5) 8+3=11 → 1011, 6+3=9 → 10011011 1001. (6) 0.011₂. (7) Gray 11101; back 10110.

Interactive exam

Number systems and conversions

Based on: Rojas / Floyd cap. 2 — CALETAS

0 of 0 answered

On the conversion map, the usual path from decimal to hexadecimal is…
In 101101₂, the MSB is…
45₁₀ in straight binary is…
45₁₀ in BCD is obtained by…
0.625₁₀ as a binary fraction (×2, bits top to bottom) is…
1011₂ to Gray code (copy MSB, then XOR with the bit on the left) is…
LSB stands for…
2D₁₆ to binary, in groups of 4 bits, is…

Next opens the Hamming code assignment (partial I: review + (7,4)). Then Boolean algebra.

Mark the unit on the study path.