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.
Number systems
Section titled “Number systems”A positional system gives each digit a weight: a power of the base, counting from the right (position 0).
| System | Base | Digits | Example |
|---|---|---|---|
| Decimal | 10 | 0–9 | 45₁₀ |
| Binary | 2 | 0, 1 | 101101₂ |
| Octal | 8 | 0–7 | 55₈ |
| Hexadecimal | 16 | 0–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:
| Acronym | English | Meaning | Where it sits | Weight |
|---|---|---|---|---|
| MSB | Most Significant Bit | the bit that counts the most | left end | the largest (in 8 bits: 128) |
| LSB | Least Significant Bit | the bit that counts the least | right end | the 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 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|
| bit | 1 | 0 | 1 | 1 | 0 | 1 |
| weight | 32 | 16 | 8 | 4 | 2 | 1 |
| 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.
| Hex | Binary (nibble) | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Octal is the same with 3 bits (8 combinations): 0 → 000 … 7 → 111.
Conversions
Section titled “Conversions”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.
↔ weights / ÷2
↔ groups of 3
↔ groups of 4
Binary → decimal
Section titled “Binary → decimal”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 | 5 | 4 | 3 | 2 | 1 | 0 |
|---|---|---|---|---|---|---|
| bit | 1 | 0 | 1 | 1 | 0 | 1 |
| weight | 32 | 16 | 8 | 4 | 2 | 1 |
| adds | 32 | — | 8 | 4 | — | 1 |
| 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 bit | Operation | Result |
|---|---|---|
1 (MSB) | start with that bit | 1 |
0 | 1 × 2 + 0 | 2 |
1 | 2 × 2 + 1 | 5 |
1 | 5 × 2 + 1 | 11 |
0 | 11 × 2 + 0 | 22 |
1 (LSB) | 22 × 2 + 1 | 45 |
Again 45₁₀.
What Horner’s rule is
Section titled “What Horner’s rule is”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.
Decimal → binary (divide by 2)
Section titled “Decimal → binary (divide by 2)”Divide by 2, write the remainder (0 or 1). Read binary bottom to top (last remainder is the MSB).
45₁₀:
45 ÷ 2 = 22 remainder 122 ÷ 2 = 11 remainder 011 ÷ 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).
Binary ↔ octal (groups of 3)
Section titled “Binary ↔ octal (groups of 3)”From the LSB, group 3 bits. Pad with zeros on the left if needed. Each group is one octal digit.
101101₂ → 101 101 → 55₈
The other way: each octal digit → 3 bits. 153₈ → 001 101 011 → 1101011₂.
Binary ↔ hexadecimal (groups of 4)
Section titled “Binary ↔ hexadecimal (groups of 4)”Same idea, 4 bits at a time.
101101₂ → 0010 1101 → 2D₁₆
2F₁₆ → 0010 1111 → 101111₂ = 32+8+4+2+1 = 47₁₀.
Decimal ↔ hexadecimal
Section titled “Decimal ↔ hexadecimal”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:
- Decimal → binary (÷ 2):
45₁₀=101101₂(already done above). - Binary → hex (groups of 4 from the LSB). Six bits left: pad zeros on the left →
0010 1101. - Each nibble is a hex digit:
0010= 2,1101= D →2D₁₆.
Back (2D₁₆ → decimal), via binary:
- Each hex digit → 4 bits:
2=0010,D=1101→00101101₂. - 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 → 2Read remainders bottom to top: 2D₁₆. Back: 2×16 + 13 = 45.
Fractional part
Section titled “Fractional part”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.
Decimal → binary (fraction)
Section titled “Decimal → binary (fraction)”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₁₀:
| Step | Calculation | Bit out | Fraction left |
|---|---|---|---|
| 1 | 0.625 × 2 = 1.250 | 1 | 0.250 |
| 2 | 0.250 × 2 = 0.500 | 0 | 0.500 |
| 3 | 0.500 × 2 = 1.000 | 1 | 0 (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.
Binary → decimal (fraction)
Section titled “Binary → decimal (fraction)”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₂:
| Bit | Weight | Adds |
|---|---|---|
1 (next to the point) | 0.5 | 0.5 |
0 | 0.25 | — |
1 | 0.125 | 0.125 |
0.5 + 0.125 = 0.625₁₀. With the integer part: 101.101₂ = 5 + 0.625 = 5.625₁₀.
Octal and hex (fraction)
Section titled “Octal and hex (fraction)”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).
Codes that come with this unit
Section titled “Codes that come with this unit”In the same chapter 2, after converting, you get BCD, excess-3, Gray, and parity (parity is finished in Hamming).
BCD is not binary
Section titled “BCD is not binary”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; 1010…1111 are not BCD digits):
| Digit | BCD (4 bits) | Digit | BCD |
|---|---|---|---|
| 0 | 0000 | 5 | 0101 |
| 1 | 0001 | 6 | 0110 |
| 2 | 0010 | 7 | 0111 |
| 3 | 0011 | 8 | 1000 |
| 4 | 0100 | 9 | 1001 |
45₁₀ in BCD, digit by digit:
- The
4→ table →0100 - The
5→0101 - 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: 5 → 0101, 9 → 1001 → 0101 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”.
Excess-3
Section titled “Excess-3”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 → 1100 → 1000 1100.
It shows up in BCD arithmetic (74LS83 later). Here you only need to build it digit by digit.
Gray code
Section titled “Gray code”Gray code (reflected binary) is built so that going to the next number flips only one bit. In ordinary binary, 7 → 8 is 0111 → 1000: 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):
| Decimal | Binary | Gray |
|---|---|---|
| 0 | 000 | 000 |
| 1 | 001 | 001 |
| 2 | 010 | 011 |
| 3 | 011 | 010 |
| 4 | 100 | 110 |
| 5 | 101 | 111 |
| 6 | 110 | 101 |
| 7 | 111 | 100 |
Binary → Gray
Section titled “Binary → Gray”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:
| MSB | LSB | |||
|---|---|---|---|---|
| Binary | 1 | 0 | 1 | 1 |
| Gray | 1 (copy) | 1 XOR 0 = 1 | 0 XOR 1 = 1 | 1 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=1 → 111011.
Gray → binary (back)
Section titled “Gray → binary (back)”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=1 → 1011₂ (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.
- Convert
53₁₀to binary, octal, and hexadecimal. - Convert
1101110₂to decimal, octal, and hex. - Convert
3A₁₆to binary and decimal. - Write
86₁₀in straight binary and in BCD. How do they differ? - Write
86₁₀in excess-3. 0.375₁₀to fractional binary.- 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 → 1001 → 1011 1001. (6) 0.011₂. (7) Gray 11101; back 10110.
Number systems and conversions
Based on: Rojas / Floyd cap. 2 — CALETAS
0 of 0 answered
Sign in with CALETAS to sync this result across devices.
Sign in with CALETASNext step
Section titled “Next step”Next opens the Hamming code assignment (partial I: review + (7,4)). Then Boolean algebra.
Mark the unit on the study path.