Number Systems and Codes

Positional Number Systems and Polynomial Representation

Numerical data in computing systems is expressed using positional number representation. While the decimal system is ubiquitous in human calculation, practical electronic devices rely primarily on two-state physical elements. Consequently, digital machines represent numbers and perform arithmetic using the binary number system, which utilizes only two symbols: 00 and 11.

An ordinary decimal number represents a polynomial in powers of 1010. For example, the decimal number 123.45123.45 represents the polynomial expansion:

123.45=1×102+2×101+3×100+4×10−1+5×10−2123.45 = 1 \times 10^2 + 2 \times 10^1 + 3 \times 10^0 + 4 \times 10^{-1} + 5 \times 10^{-2}

In general positional notation, the number 1010 is referred to as the base or radix of the system. In a system with base bb, a positive number NN represents the polynomial:

N=aq−1bq−1+aq−2bq−2+×××+a1b1+a0b0+a−1b−1+a−2b−2+×××+a−pb−p=∑i=−pq−1aibiN = a_{q-1} b^{q-1} + a_{q-2} b^{q-2} + \times \times \times + a_1 b^1 + a_0 b^0 + a_{-1} b^{-1} + a_{-2} b^{-2} + \times \times \times + a_{-p} b^{-p} = \sum_{i=-p}^{q-1} a_i b^i

where:

  • The base bb is an integer greater than 11.

  • The coefficients aia_i are integers satisfying the inequality 0≤ai≤b−10 \le a_i \le b - 1

  • The digit sequence aq−1aq−2×××a0a_{q-1} a_{q-2} \times \times \times a_0 constitutes the integral part of NN, comprising qq digits.

  • The digit sequence a−1a−2×××a−pa_{-1} a_{-2} \times \times \times a_{-p} constitutes the fractional part of NN, comprising pp digits.

  • A radix point separates the integral and fractional parts.

  • The digit a−pa_{-p} is the least significant digit (LSD).

  • The digit aq−1a_{q-1} is the most significant digit (MSD).

When the base b=2b = 2, the system is called the binary number system. For example, the binary number 1101.0121101.01_2 represents the polynomial expansion:

1101.012=1×23+1×22+0×21+1×20+0×2−1+1×2−21101.01_2 = 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 + 0 \times 2^{-1} + 1 \times 2^{-2}

Evaluating this polynomial gives 8+4+0+1+0+0.25=13.25108 + 4 + 0 + 1 + 0 + 0.25 = 13.25_{10}. Formally, this binary number is expressed as:

1101.012=∑i=−23ai2i1101.01_2 = \sum_{i=-2}^{3} a_i 2^i

where a−2=1a_{-2} = 1, a−1=0a_{-1} = 0, a0=1a_0 = 1, a1=0a_1 = 0, a2=1a_2 = 1, and a3=1a_3 = 1

A number NN in base bb is denoted as (N)b(N)_b. When the base is omitted, base 1010 is implicitly assumed.

Representations of Integers in Various Bases

Base 2

Base 4

Base 8

Base 10

Base 12

00000000

00

00

00

00

00010001

11

11

11

11

00100010

22

22

22

22

00110011

33

33

33

33

01000100

1010

44

44

44

01010101

1111

55

55

55

01100110

1212

66

66

66

01110111

1313

77

77

77

10001000

2020

1010

88

88

10011001

2121

1111

99

99

10101010

2222

1212

1010

α\alpha

10111011

2323

1313

1111

β\beta

11001100

3030

1414

1212

1010

11011101

3131

1515

1313

1111

11101110

3232

1616

1414

1212

11111111

3333

1717

1515

1313

Digit Complements

The complement of a digit aa, denoted a′a', in base bb is defined as the difference between the largest allowable digit in base bb and the digit aa:

a′=(b−1)−aa' = (b - 1) - a

  • In the binary number system (b=2b = 2), the complements are 0′=10' = 1 and 1′=01' = 0. This is known as the 1's complement.

  • In the decimal number system (b=10b = 10), the largest digit is 99. The complement of a digit aa is 9−a9 - a, known as the 9's complement. For example, the 9's complement of 33 is 9−3=69 - 3 = 6

Number System Base Conversions

When converting a number (N)b1(N)_{b_1} from base b1b_1 to base b2b_2, two operational cases are distinguished based on which base arithmetic is used.

Case 1: Conversion when b1<b2b_1 < b_2

When b1<b2b_1 < b_2, it is convenient to use base-b2b_2 arithmetic. The number (N)b1(N)_{b_1} is expressed as a polynomial in powers of b1b_1, and the terms are evaluated using base-b2b_2 arithmetic operations.

Conversion Example: Octal to Decimal (b1=8b_1 = 8, b2=10b_2 = 10)

Convert (432.2)8(432.2)_8 to base 1010:

(432.2)8=4×82+3×81+2×80+2×8−1(432.2)_8 = 4 \times 8^2 + 3 \times 8^1 + 2 \times 8^0 + 2 \times 8^{-1}

(432.2)8=4×64+3×8+2×1+2×0.125=256+24+2+0.25=(282.25)10(432.2)_8 = 4 \times 64 + 3 \times 8 + 2 \times 1 + 2 \times 0.125 = 256 + 24 + 2 + 0.25 = (282.25)_{10}

Conversion Example: Binary to Decimal (b1=2b_1 = 2, b2=10b_2 = 10)

Convert (1101.01)2(1101.01)_2 to base 1010:

(1101.01)2=1×23+1×22+0×21+1×20+0×2−1+1×2−2(1101.01)_2 = 1 \times 2^3 + 1 \times 2^2 + 0 \times 2^1 + 1 \times 2^0 + 0 \times 2^{-1} + 1 \times 2^{-2}

(1101.01)2=8+4+0+1+0+0.25=(13.25)10(1101.01)_2 = 8 + 4 + 0 + 1 + 0 + 0.25 = (13.25)_{10}

Case 2: Conversion when b1>b2b_1 > b_2

When b1>b2b_1 > b_2, it is convenient to use base-b1b_1 arithmetic. The conversion processes integral and fractional parts separately.

Integral Part Conversion Algorithm

For an integer (N)b1(N)_{b_1} represented in base b2b_2 as:

(N)b1=aq−1b2q−1+aq−2b2q−2+×××+a1b21+a0b20(N)_{b_1} = a_{q-1} b_2^{q-1} + a_{q-2} b_2^{q-2} + \times \times \times + a_1 b_2^1 + a_0 b_2^0

Dividing (N)b1(N)_{b_1} by b2b_2 yields:

(N)b1b2=aq−1b2q−2+aq−2b2q−3+×××+a1+a0b2=Q0+a0b2\frac{(N)_{b_1}}{b_2} = a_{q-1} b_2^{q-2} + a_{q-2} b_2^{q-3} + \times \times \times + a_1 + \frac{a_0}{b_2} = Q_0 + \frac{a_0}{b_2}

The remainder of this division equals the least significant digit a0a_0. Dividing the quotient Q0Q_0 by b2b_2 gives:

Q0b2=aq−1b2q−3+×××+a2+a1b2=Q1+a1b2\frac{Q_0}{b_2} = a_{q-1} b_2^{q-3} + \times \times \times + a_2 + \frac{a_1}{b_2} = Q_1 + \frac{a_1}{b_2}

This process of successive division is repeated until the quotient Qq−1=0Q_{q-1} = 0. The remainders generated at each step correspond to the digits a0,a1,…,aq−1a_0, a_1, \dots, a_{q-1}.

Integer Example 1: Decimal (548)10(548)_{10} to Octal (b2=8b_2 = 8)

Division (Qi=Qi−1/8Q_i = Q_{i-1} / 8)

Quotient QiQ_i

Remainder ri=air_i = a_i

548/8548 / 8

6868

4=a04 = a_0

68/868 / 8

88

4=a14 = a_1

8/88 / 8

11

0=a20 = a_2

1/81 / 8

00

1=a31 = a_3

Result: (548)10=(1044)8(548)_{10} = (1044)_8

Integer Example 2: Decimal (345)10(345)_{10} to Base 66 (b2=6b_2 = 6)

Division (Qi=Qi−1/6Q_i = Q_{i-1} / 6)

Quotient QiQ_i

Remainder ri=air_i = a_i

345/6345 / 6

5757

3=a03 = a_0

57/657 / 6

99

3=a13 = a_1

9/69 / 6

11

3=a23 = a_2

1/61 / 6

00

1=a31 = a_3

Result: (345)10=(1333)6(345)_{10} = (1333)_6

Reconversion check to Base 10: (1333)6=1×63+3×62+3×61+3×60=216+108+18+3=(345)10(1333)_6 = 1 \times 6^3 + 3 \times 6^2 + 3 \times 6^1 + 3 \times 6^0 = 216 + 108 + 18 + 3 = (345)_{10}

Fractional Part Conversion Algorithm

For a fraction (N)b1(N)_{b_1} expressed in base b2b_2 as:

(N)b1=a−1b2−1+a−2b2−2+×××+a−pb2−p(N)_{b_1} = a_{-1} b_2^{-1} + a_{-2} b_2^{-2} + \times \times \times + a_{-p} b_2^{-p}

Multiplying (N)b1(N)_{b_1} by b2b_2 yields:

b2×(N)b1=a−1+a−2b2−1+×××+a−pb2−p+1b_2 \times (N)_{b_1} = a_{-1} + a_{-2} b_2^{-1} + \times \times \times + a_{-p} b_2^{-p+1}

  • If this product is less than 11, then a−1=0a_{-1} = 0

  • If this product is greater than or equal to 11, then a−1a_{-1} equals the integral part of the product.

The next digit a−2a_{-2} is found by multiplying the remaining fractional part by b2b_2 and extracting its integral part. This process is repeated for successive digits. It does not necessarily terminate if the fraction cannot be represented exactly with a finite number of digits in base b2b_2

Fractional Example 1: Decimal (0.3125)10(0.3125)_{10} to Octal (b2=8b_2 = 8)
  • 0.3125×8=2.5000  ⟹  0.3125 \times 8 = 2.5000 \implies Integral part a−1=2a_{-1} = 2

  • 0.5000×8=4.0000  ⟹  0.5000 \times 8 = 4.0000 \implies Integral part a−2=4a_{-2} = 4

Result: (0.3125)10=(0.24)8(0.3125)_{10} = (0.24)_8

Fractional Example 2: Decimal (0.375)10(0.375)_{10} to Binary (b2=2b_2 = 2)
  • 0.375×2=0.750  ⟹  0.375 \times 2 = 0.750 \implies Integral part a−1=0a_{-1} = 0

  • 0.750×2=1.500  ⟹  0.750 \times 2 = 1.500 \implies Integral part a−2=1a_{-2} = 1

  • 0.500×2=1.000  ⟹  0.500 \times 2 = 1.000 \implies Integral part a−3=1a_{-3} = 1

Result: (0.375)10=(0.011)2(0.375)_{10} = (0.011)_2

Fractional Example 3: Decimal (432.354)10(432.354)_{10} to Binary (b2=2b_2 = 2)

Integral Part Conversion (43210432_{10}):

Division

Quotient QiQ_i

Remainder ri=air_i = a_i

432/2432 / 2

216216

0=a00 = a_0

216/2216 / 2

108108

0=a10 = a_1

108/2108 / 2

5454

0=a20 = a_2

54/254 / 2

2727

0=a30 = a_3

27/227 / 2

1313

1=a41 = a_4

13/213 / 2

66

1=a51 = a_5

6/26 / 2

33

0=a60 = a_6

3/23 / 2

11

1=a71 = a_7

1/21 / 2

00

1=a81 = a_8

Integral result: (432)10=(110110000)2(432)_{10} = (110110000)_2

Fractional Part Conversion (0.354100.354_{10}):

  • 0.354×2=0.708  ⟹  a−1=00.354 \times 2 = 0.708 \implies a_{-1} = 0

  • 0.708×2=1.416  ⟹  a−2=10.708 \times 2 = 1.416 \implies a_{-2} = 1

  • 0.416×2=0.832  ⟹  a−3=00.416 \times 2 = 0.832 \implies a_{-3} = 0

  • 0.832×2=1.664  ⟹  a−4=10.832 \times 2 = 1.664 \implies a_{-4} = 1

  • 0.664×2=1.328  ⟹  a−5=10.664 \times 2 = 1.328 \implies a_{-5} = 1

  • 0.328×2=0.656  ⟹  a−6=00.328 \times 2 = 0.656 \implies a_{-6} = 0

  • 0.656×2=1.312  ⟹  a−7=10.656 \times 2 = 1.312 \implies a_{-7} = 1

Fractional result: (0.354)10=(0.0101101… )2(0.354)_{10} = (0.0101101\dots)_2

Combined conversion: (432.354)10=(110110000.0101101… )2(432.354)_{10} = (110110000.0101101\dots)_2 Reconversion to base 1010 of this truncated representation yields (432.3515)10(432.3515)_{10}.

Direct Base Conversion Shortcut (b2=b1kb_2 = b_1^k)

When converting between bases where b2=b1kb_2 = b_1^k, grouping digits allows immediate conversion without intermediate polynomial arithmetic.

Octal to Binary and Binary to Octal (8=23,k=38 = 2^3, k = 3)

Each octal digit maps directly to a group of three binary digits, starting from the radix point.

  • Octal to Binary: (123.4)8=(001 010 011.100)2(123.4)_8 = (001\ 010\ 011 . 100)_2

  • Binary to Octal: (1010110.0101)2=(001 010 110.010 100)2=(126.24)8(1010110.0101)_2 = (001\ 010\ 110 . 010\ 100)_2 = (126.24)_8

Binary to Hexadecimal (16=24,k=416 = 2^4, k = 4)

Conversion to hexadecimal uses groups of four binary digits for each hex digit.

Binary Arithmetic Operations

Binary arithmetic follows rules analogous to decimal arithmetic. The fundamental single-bit operations are summarized below.

Elementary Binary Operations

Bit aa

Bit bb

Sum a+ba + b

Carry

Difference a−ba - b

Borrow

Product a⋅ba \cdot b

00

00

00

00

00

00

00

00

11

11

00

11

11

00

11

00

11

00

11

00

00

11

11

00

11

00

00

11

Addition

Binary addition adds corresponding bits starting from the least significant position. If a carry of 11 is produced, it is added to the next column to the left.

Addition Example

\begin{array}{r@{\quad}l}\n1111 & \text{(carries of } 1\text{)} \\\n1111.01_2 & (15.25_{10}) \\\n+ \; 0111.10_2 & (7.50_{10}) \\\n\hline\n10110.11_2 & (22.75_{10})\n\end{array}

Subtraction

When subtracting bits a−ba - b, if a borrow of 11 occurs:

  1. If the next left digit of the minuend is 11, it is changed to 00, and subtraction proceeds.

  2. If the next left digit of the minuend is 00, it is changed to 11, as is each successive minuend digit to the left that equals 00. The first minuend digit to the left that equals 11 is changed to 00, and subtraction continues.

Subtraction Example

\begin{array}{r@{\quad}l}\n1 \phantom{.00} & \text{(borrows of } 1\text{)} \\\n10010.11_2 & (18.75_{10}) \\\n- \; 01100.10_2 & (12.50_{10}) \\\n\hline\n00110.01_2 & (6.25_{10})\n\end{array}

Multiplication

Binary multiplication is performed by generating partial products via repeated bitwise multiplication and summing them using shift-and-add steps.

Multiplication Example

\begin{array}{r@{\quad}l}\n11001.1_2 & (25.5_{10}) \\\n\times \; 110.1_2 & (6.5_{10}) \\\n\hline\n110011 &\n0000000 &\n11001100 &\n+ \; 110011000 &\n\hline\n10100101.11_2 & (165.75_{10})\n\end{array}

Division

Binary division is executed through successive conditional subtractions, matching the long division procedure of decimal arithmetic.

Division Example

Divide 100010011021000100110_2 by 11001211001_2:

\begin{array}{r@{\quad}l}\n10110_2 & \text{(quotient)} \\\n11001_2 \; \overline{) \; 1000100110_2} &\n\underline{- \; 11001\phantom{0000}} &\n00100101 &\n\underline{- \; 11001\phantom{0}} &\n0011001 &\n\underline{- \; 11001} &\n00000_2 & \text{(remainder)}\n\end{array}

Weighted Binary Codes for Decimal Digits

Human-machine communication requires representing the 1010 decimal digits (0,1,…,90, 1, \dots, 9) in binary form. At least 44 binary digits (bits) are necessary, as 23=8<102^3 = 8 < 10 and 24=16≥102^4 = 16 \ge 10. Since 44 bits afford 1616 distinct combinations, multiple code mappings exist.

In a weighted code, each binary position is assigned a specific numerical weight w1,w2,w3,w4w_1, w_2, w_3, w_4. A decimal digit NN represented by the binary sequence x4x3x2x1x_4 x_3 x_2 x_1 satisfies:

N=w4x4+w3x3+w2x2+w1x1N = w_4 x_4 + w_3 x_3 + w_2 x_2 + w_1 x_1

The binary sequence x4x3x2x1x_4 x_3 x_2 x_1 is called a code word.

Examples of Weighted Binary Codes

Decimal Digit

BCD (8 4 2 1)

2 4 2 1 Code

6 4 2 -3 Code

00

00000000

00000000

00000000

11

00010001

00010001

01010101

22

00100010

00100010

00100010

33

00110011

00110011

10011001

44

01000100

01000100

01000100

55

01010101

10111011

10111011

66

01100110

11001100

01100110

77

01110111

11011101

11011101

88

10001000

11101110

10101010

99

10011001

11111111

11111111

Code Characteristics and Properties
  1. Binary-Coded-Decimal (BCD) / 8 4 2 1 Code:    Weights are 8,4,2,18, 4, 2, 1. Each decimal digit maps directly to its traditional 44--bit binary equivalent. For example, decimal 55 is 010120101_2, since 8(0)+4(1)+2(0)+1(1)=58(0) + 4(1) + 2(0) + 1(1) = 5

  2. Negative Weights:    Weights can be negative, as in the (6,4,2,−3)(6, 4, 2, -3) code. In this code, decimal 55 is represented as 101121011_2 because:    6(1)+4(0)+2(1)+(−3)(1)=6+0+2−3=56(1) + 4(0) + 2(1) + (-3)(1) = 6 + 0 + 2 - 3 = 5

  3. Self-Complementing Codes:    A code is self-complementing if the code word for the 99's complement of NN (i.e., 9−N9 - N) is obtained by bitwise inversion (interchanging all 11s and 00s) of the code word for NN

    • In the (2,4,2,1)(2, 4, 2, 1) code: Decimal 22 is 00100010. Its 99's complement, decimal 77, is 11011101 (the bitwise inversion of 00100010).

    • In the (6,4,2,−3)(6, 4, 2, -3) code: Decimal 33 is 10011001. Its 99's complement, decimal 66, is 01100110 (the bitwise inversion of 10011001).

    • The standard BCD (84218 4 2 1) code is not self-complementing.        Theorem on Self-Complementing Codes:    A necessary condition for a weighted code to be self-complementing is that the sum of its weights must equal 99:    ∑i=14wi=9\sum_{i=1}^{4} w_i = 9    

    • There exist only four positively weighted self-complementing codes: (2,4,2,1)(2, 4, 2, 1), (3,3,2,1)(3, 3, 2, 1), (4,3,1,1)(4, 3, 1, 1), and (5,2,1,1)(5, 2, 1, 1).

    • There exist 13 self-complementing codes utilizing both positive and negative weights.

Nonweighted Binary Codes and Gray Code

Nonweighted codes do not assign positional values to bit positions.

Nonweighted Codes Comparison

Decimal Digit

Excess-3 Code

Cyclic Code

00

00110011

00000000

11

01000100

00010001

22

01010101

00110011

33

01100110

00100010

44

01110111

01100110

55

10001000

01110111

66

10011001

10111011

77

10101010

10011001

88

10111011

11001100

99

11001100

01000100

Excess-3 Code

The Excess-3 code is derived by adding 001120011_2 (3103_{10}) to each standard BCD code word. For instance, decimal 77 in Excess-3 is:

01112+00112=101020111_2 + 0011_2 = 1010_2

Excess-3 is a self-complementing code. For example, decimal 22 (010120101_2) and decimal 77 (101021010_2) are bitwise inversions of each other.

Cyclic Codes

Cyclic codes have the property that adjacent code words differ in exactly one bit position. In addition, the code words for decimal 00 and decimal 99 differ in only one bit position.

Gray Code

The Gray code is a fundamental cyclic code widely used in analog-to-digital conversion and shaft encoders.

Complete Four-Bit Gray Code

Decimal Number

Gray Code (g3g2g1g0g_3 g_2 g_1 g_0)

Binary Number (b3b2b1b0b_3 b_2 b_1 b_0)

00

00000000

00000000

11

00010001

00010001

22

00110011

00100010

33

00100010

00110011

44

01100110

01000100

55

01110111

01010101

66

01010101

01100110

77

01000100

01110111

88

11001100

10001000

99

11011101

10011001

1010

11111111

10101010

1111

11101110

10111011

1212

10101010

11001100

1313

10111011

11011101

1414

10011001

11101110

1515

10001000

11111111

Binary to Gray Code Conversion

Let gn…g1g0g_n \dots g_1 g_0 denote an (n+1)(n+1)--bit Gray code word, and bn…b1b0b_n \dots b_1 b_0 denote the corresponding binary number (where subscript 00 is the LSB and nn is the MSB).

Each Gray bit gig_i is calculated as:

gi=bi⊕bi+1for 0≤i≤n−1g_i = b_i \oplus b_{i+1} \quad \text{for } 0 \le i \le n-1

gn=bng_n = b_n

where ⊕\oplus represents the modulo-2 sum (Exclusive-OR):

  • 0⊕0=00 \oplus 0 = 0

  • 0⊕1=10 \oplus 1 = 1

  • 1⊕0=11 \oplus 0 = 1

  • 1⊕1=01 \oplus 1 = 0

Binary to Gray Example

Convert binary 1011012101101_2 (b5b4b3b2b1b0b_5 b_4 b_3 b_2 b_1 b_0) to Gray code:

  • g5=b5=1g_5 = b_5 = 1

  • g4=b5⊕b4=1⊕0=1g_4 = b_5 \oplus b_4 = 1 \oplus 0 = 1

  • g3=b4⊕b3=0⊕1=1g_3 = b_4 \oplus b_3 = 0 \oplus 1 = 1

  • g2=b3⊕b2=1⊕1=0g_2 = b_3 \oplus b_2 = 1 \oplus 1 = 0

  • g1=b2⊕b1=1⊕0=1g_1 = b_2 \oplus b_1 = 1 \oplus 0 = 1

  • g0=b1⊕b0=0⊕1=1g_0 = b_1 \oplus b_0 = 0 \oplus 1 = 1

Result: Gray code word is 111011111011

Gray Code to Binary Conversion Algorithm

To convert from Gray code to binary, evaluate bits from MSB to LSB:

  1. Set bn=gnb_n = g_n

  2. For i<ni < n:

    • Set bi=gib_i = g_i if the number of 11s preceding gig_i in the Gray word is even (zero is considered an even count).

    • Set bi=gi′b_i = g_i' (complement of gig_i) if the number of 11s preceding gig_i is odd.

Gray to Binary Example

Convert Gray code 10010111001011 to binary:

  • b6=g6=1b_6 = g_6 = 1

  • Preceding 11s for g5(0)g_5(0) is 11 (odd)   ⟹  b5=0′=1\implies b_5 = 0' = 1

  • Preceding 11s for g4(0)g_4(0) is 11 (odd)   ⟹  b4=0′=1\implies b_4 = 0' = 1

  • Preceding 11s for g3(1)g_3(1) is 11 (odd)   ⟹  b3=1′=0\implies b_3 = 1' = 0

  • Preceding 11s for g2(0)g_2(0) is 22 (even)   ⟹  b2=0\implies b_2 = 0

  • Preceding 11s for g1(1)g_1(1) is 22 (even)   ⟹  b1=1\implies b_1 = 1

  • Preceding 11s for g0(1)g_0(1) is 33 (odd)   ⟹  b0=1′=0\implies b_0 = 1' = 0

Result: Binary number is 111001021110010_2

Reflected Code Construction

An nn--bit Gray code is generated by reflecting an (n−1)(n-1)--bit code about a central axis, then prefixing a MSB of 00 above the axis and 11 below the axis.

Reflection of Gray codes

Error-Detecting Binary Codes and Parity Schemes

Physical transmission channels are prone to electronic noise and component failures. While the probability of a single-bit error is finite, simultaneous multiple-bit errors occur with significantly lower probability.

Minimum Distance of a Code

The distance between two binary code words is the number of digit positions in which they differ. For example, the distance between 10101010 and 01000100 is 33

The minimum distance (dmind_{\text{min}}) of a code is the smallest distance between any pair of valid code words in that code:

  • Standard BCD and Excess-3 have dmin=1d_{\text{min}} = 1

  • A code is single-error-detecting if and only if dmin≥2d_{\text{min}} \ge 2

  • To create an nn--bit single-error-detecting code, no more than half of the possible 2n2^n combinations can be used (2n−12^{n-1} words). To encode 1010 decimal digits with error detection, at least 55 bits are required (25−1=16≥102^{5-1} = 16 \ge 10).

Parity Check Methods

A parity bit pp is appended to each code word to ensure the total count of 11s across all digits is either even (even parity) or odd (odd parity). Even parity detects any odd number of bit errors.

Error-Detecting Codes Comparison

Decimal Digit

Even-Parity BCD (8 4 2 1 p)

2-out-of-5 Code (0 1 2 4 7)

00

0000000000

0001100011

11

0001100011

1100011000

22

0010100101

1010010100

33

0011000110

0110001100

44

0100101001

1001010010

55

0101001010

0101001010

66

0110001100

0011000110

77

0111101111

1000110001

88

1000110001

0100101001

99

1001010010

0010100101

  1. Even-Parity BCD: Appends a 5th parity bit pp to standard BCD to maintain an even total count of 11s.

  2. 2-out-of-5 Code: Each 5-bit word contains exactly two 11s. Except for decimal 00, it is derived from the weighted (1,2,4,7)(1, 2, 4, 7) code. Any single bit flip transforms a valid word into an invalid word containing either one or three 11s, triggering detection.

Error-Correcting Codes and Hamming Code Construction

To correct errors automatically, the minimum distance must be increased:

  • dmin=3d_{\text{min}} = 3: Allows single-error correction OR double-error detection.

  • dmin=4d_{\text{min}} = 4: Allows single-error correction AND double-error detection simultaneously.

Hamming Error-Correcting Code

A Hamming code adds kk parity-checking bits (p1,p2,…,pkp_1, p_2, \dots, p_k) to mm message bits to form an (m+k)(m + k)--bit code word. The bit positions are numbered 11 through m+km + k, starting from position 11 at the MSB.

Mathematical Constraint on Check Bits

The number of check bits kk must be sufficient to identify all m+km + k single-error positions, plus the "no error" condition:

2k≥m+k+12^k \ge m + k + 1

For a BCD message (m=4m = 4): 2k≥4+k+1  ⟹  2k≥5+k2^k \ge 4 + k + 1 \implies 2^k \ge 5 + k

The smallest integer satisfying this is k=3k = 3. Thus, the total code length is m+k=7m + k = 7 bits.

Bit Placement Rule

To allow check bits to be computed independently, parity bits are placed at positions corresponding to powers of 22: positions 1,2,4,…,2k−11, 2, 4, \dots, 2^{k-1}.

  • For m=4,k=3m = 4, k = 3:

    • Position 11: Parity bit p1p_1

    • Position 22: Parity bit p2p_2

    • Position 33: Message bit m1m_1

    • Position 44: Parity bit p3p_3

    • Position 55: Message bit m2m_2

    • Position 66: Message bit m3m_3

    • Position 77: Message bit m4m_4

Position Number Table

Each parity check targets specific positions such that the resulting binary evaluation c3c2c1c_3 c_2 c_1 (the position or syndrome number) directly indicates the 1-based decimal index of the erroneous bit. If c3c2c1=000c_3 c_2 c_1 = 000, no error has occurred.

Error Position

Position Number (c3c2c1c_3 c_2 c_1)

Parity Checks Involved

00 (No error)

000000

None

11

001001

p1p_1 check (positions 1, 3, 5, 7)

22

010010

p2p_2 check (positions 2, 3, 6, 7)

33

011011

p1,p2p_1, p_2 checks

44

100100

p3p_3 check (positions 4, 5, 6, 7)

55

101101

p1,p3p_1, p_3 checks

66

110110

p2,p3p_2, p_3 checks

77

111111

p1,p2,p3p_1, p_2, p_3 checks

Parity Generation Rules
  • p1p_1 is chosen to establish even parity across positions 1,3,5,71, 3, 5, 7

  • p2p_2 is chosen to establish even parity across positions 2,3,6,72, 3, 6, 7

  • p3p_3 is chosen to establish even parity across positions 4,5,6,74, 5, 6, 7

Complete Hamming Code for BCD

Decimal Digit

Pos 1 (p1p_1)

Pos 2 (p2p_2)

Pos 3 (m1m_1)

Pos 4 (p3p_3)

Pos 5 (m2m_2)

Pos 6 (m3m_3)

Pos 7 (m4m_4)

00

00

00

00

00

00

00

00

11

11

11

00

11

00

00

11

22

00

11

00

11

00

11

00

33

11

00

00

00

00

11

11

44

11

00

00

11

11

00

00

55

00

11

00

00

11

00

11

66

11

11

00

00

11

11

00

77

00

00

00

11

11

11

11

88

11

11

11

00

00

00

00

99

00

00

11

11

00

00

11

Step-by-Step Error Correction Example

Suppose decimal digit 11 (11010011101001) is transmitted, but bit 55 experiences an error, resulting in 11011011101101

Perform parity checks on received bits (11011011101101):

  1. 4-5-6-7 Parity Check: Bits at positions 4, 5, 6, 7 are 1,1,0,11, 1, 0, 1. Sum = 33 (odd)   ⟹  c3=1\implies c_3 = 1

  2. 2-3-6-7 Parity Check: Bits at positions 2, 3, 6, 7 are 1,0,0,11, 0, 0, 1. Sum = 22 (even)   ⟹  c2=0\implies c_2 = 0

  3. 1-3-5-7 Parity Check: Bits at positions 1, 3, 5, 7 are 1,0,1,11, 0, 1, 1. Sum = 33 (odd)   ⟹  c1=1\implies c_1 = 1

The error position number c3c2c1=1012=510c_3 c_2 c_1 = 101_2 = 5_{10}. This isolates the error precisely to position 55. Complementing position 55 (1→01 \to 0) recovers the correct code word 11010011101001

Extended Hamming Code (dmin=4d_{\text{min}} = 4)

By adding an 8th overall parity bit (p4p_4) covering all 7 previous bits:

  • If an overall parity error occurs AND c3c2c1≠000c_3 c_2 c_1 \ne 000, a single error occurred at position c3c2c1c_3 c_2 c_1

  • If overall parity is satisfied BUT c3c2c1≠000c_3 c_2 c_1 \ne 000, a double error occurred.

  • If overall parity fails AND c3c2c1=000c_3 c_2 c_1 = 000, the 8th parity bit itself is in error.

Comprehensive Chapter Problems and Analytical Solutions

Problem 1-1: Base Conversions

Perform the following conversions:

  • (a) (1431)8(1431)_8 to base 10:   1×83+4×82+3×81+1×80=512+256+24+1=(793)101 \times 8^3 + 4 \times 8^2 + 3 \times 8^1 + 1 \times 8^0 = 512 + 256 + 24 + 1 = (793)_{10}

  • (b) 11001010.0101211001010.0101_2 to base 10:   27+26+23+21+2−2+2−4=128+64+8+2+0.25+0.0625=(202.3125)102^7 + 2^6 + 2^3 + 2^1 + 2^{-2} + 2^{-4} = 128 + 64 + 8 + 2 + 0.25 + 0.0625 = (202.3125)_{10}

  • (c) 11001101.0101211001101.0101_2 to base 8 and base 4:

    • To Base 8: (011 001 101.010 100)2=(315.24)8(011\ 001\ 101 . 010\ 100)_2 = (315.24)_8

    • To Base 4: (11 00 11 01.01 01)2=(3031.11)4(11\ 00\ 11\ 01 . 01\ 01)_2 = (3031.11)_4

  • (d) (1984)10(1984)_{10} to base 8:

    • 1984/8=2481984 / 8 = 248 rem 00

    • 248/8=31248 / 8 = 31 rem 00

    • 31/8=331 / 8 = 3 rem 77

    • 3/8=03 / 8 = 0 rem 33

    • Result: (3700)8(3700)_8

  • (e) (1776)10(1776)_{10} to base 6:

    • 1776/6=2961776 / 6 = 296 rem 00

    • 296/6=49296 / 6 = 49 rem 22

    • 49/6=849 / 6 = 8 rem 11

    • 8/6=18 / 6 = 1 rem 22

    • 1/6=01 / 6 = 0 rem 11

    • Result: (12120)6(12120)_6

  • (f) (53.1575)10(53.1575)_{10} to base 2:

    • Integer 53=32+16+4+1=(110101)253 = 32 + 16 + 4 + 1 = (110101)_2

    • Fraction 0.1575×2=0.315(0)0.1575 \times 2 = 0.315 (0), 0.315×2=0.63(0)0.315 \times 2 = 0.63 (0), 0.63×2=1.26(1)0.63 \times 2 = 1.26 (1), 0.26×2=0.52(0)0.26 \times 2 = 0.52 (0), 0.52×2=1.04(1)0.52 \times 2 = 1.04 (1)

    • Result: (110101.00101… )2(110101.00101\dots)_2

  • (g) (3.1415)10(3.1415)_{10} to base 8 and base 2:

    • Integer 3=(3)8=(11)23 = (3)_8 = (11)_2

    • Fraction 0.1415×8=1.132(1)0.1415 \times 8 = 1.132 (1), 0.132×8=1.056(1)0.132 \times 8 = 1.056 (1), 0.056×8=0.448(0)0.056 \times 8 = 0.448 (0)

    • Result Base 8: (3.110… )8(3.110\dots)_8

    • Result Base 2: (11.00100100001… )2(11.00100100001\dots)_2

Problem 1-2: Base Determination
  • (a) Given (16)10=(100)b(16)_{10} = (100)_b, determine bb:   1×b2+0×b1+0×b0=16  ⟹  b2=16  ⟹  b=41 \times b^2 + 0 \times b^1 + 0 \times b^0 = 16 \implies b^2 = 16 \implies b = 4

  • (b) Given (292)10=(1204)b(292)_{10} = (1204)_b, determine bb:   1×b3+2×b2+0×b1+4×b0=2921 \times b^3 + 2 \times b^2 + 0 \times b^1 + 4 \times b^0 = 292   b3+2b2+4=292  ⟹  b3+2b2−288=0b^3 + 2b^2 + 4 = 292 \implies b^3 + 2b^2 - 288 = 0   Testing b=6b = 6: 216+2(36)−288=216+72−288=0  ⟹  b=6216 + 2(36) - 288 = 216 + 72 - 288 = 0 \implies b = 6

Problem 1-3: Binary Arithmetic

Given a=1010.12a = 1010.1_2, b=101.012b = 101.01_2, c=1001.12c = 1001.1_2:

  • **(a) a+c=1010.12+1001.12=100100.02a + c = 1010.1_2 + 1001.1_2 = 100100.0_2

  • **(b) a−b=1010.102−101.012=101.012a - b = 1010.10_2 - 101.01_2 = 101.01_2

  • **(c) a×c=1010.12×1001.12=111111.112a \times c = 1010.1_2 \times 1001.1_2 = 111111.11_2

  • **(d) a/b=1010.102/101.012=102a / b = 1010.10_2 / 101.01_2 = 10_2

Problem 1-4: Number System Base Identification
  • (a) 1234+5432=66661234 + 5432 = 6666: Valid for any base b≥7b \ge 7

  • (b) 41/3=1341 / 3 = 13:   4b+13=b+3  ⟹  4b+1=3b+9  ⟹  b=8\frac{4b + 1}{3} = b + 3 \implies 4b + 1 = 3b + 9 \implies b = 8

  • (c) 33/3=1133 / 3 = 11: Valid for any base b≥4b \ge 4

  • (d) 23+44+14+32=22323 + 44 + 14 + 32 = 223:   (2b+3)+(4b+4)+(b+4)+(3b+2)=2b2+2b+3(2b+3) + (4b+4) + (b+4) + (3b+2) = 2b^2 + 2b + 3   10b+13=2b2+2b+3  ⟹  2b2−8b−10=0  ⟹  b2−4b−5=0  ⟹  b=510b + 13 = 2b^2 + 2b + 3 \implies 2b^2 - 8b - 10 = 0 \implies b^2 - 4b - 5 = 0 \implies b = 5

  • (e) 302/20=12.1302 / 20 = 12.1:   3b2+22b=b+2+b−1  ⟹  3b2+2=2b2+4b+2  ⟹  b2−4b=0  ⟹  b=4\frac{3b^2 + 2}{2b} = b + 2 + b^{-1} \implies 3b^2 + 2 = 2b^2 + 4b + 2 \implies b^2 - 4b = 0 \implies b = 4

  • (f) 41=5\sqrt{41} = 5:   4b+1=5  ⟹  4b+1=25  ⟹  4b=24  ⟹  b=6\sqrt{4b + 1} = 5 \implies 4b + 1 = 25 \implies 4b = 24 \implies b = 6

Problem 1-5: Number Sequence in Decreasing Bases

Series: 10000,121,100,?,24,22,2010000, 121, 100, ?, 24, 22, 20

  • 100002=161010000_2 = 16_{10}

  • 1213=1610121_3 = 16_{10}

  • 1004=1610100_4 = 16_{10}

  • Base 5 representation of 161016_{10}: 16/5=316 / 5 = 3 rem 1  ⟹  3151 \implies 31_5

  • 246=161024_6 = 16_{10}, 227=161022_7 = 16_{10}, 208=161020_8 = 16_{10}

Missing member is 3131 (represented in base 5).