Module 1: Foundations of Digital Logic · 1.1 Number Systems & Arithmetic

Number Base Conversion Techniques

Digital engineers frequently convert numerical values between decimal, binary, octal, and hexadecimal bases. This article describes systematic manual conversion techniques without requiring a computational calculator.

Decimal to Binary Conversion

Designers convert positive decimal numbers to binary using two primary methods: repeated division by 2, and subtraction of powers of two.

Method 1: Repeated Division by 2

Divide the decimal value by 2 repeatedly and record each remainder. Continue the division until the quotient equals 0. The recorded remainders form the binary value when read in reverse order (from bottom to top).

Example: Convert decimal value 45 to binary:

Step Division Operation Quotient Remainder Bit Significance
1 45 ÷ 2 22 1 Least Significant Bit (LSB)
2 22 ÷ 2 11 0 Bit 1
3 11 ÷ 2 5 1 Bit 2
4 5 ÷ 2 2 1 Bit 3
5 2 ÷ 2 1 0 Bit 4
6 1 ÷ 2 0 1 Most Significant Bit (MSB)

Reading the remainders from Step 6 to Step 1 produces binary $101101_2$. The initial remainder indicates whether the integer is odd (1) or even (0).

Method 2: Subtraction of Descending Powers of Two

Identify the largest power of two that is less than or equal to the target value. Subtract this power of two and place a 1 at the corresponding bit position. Repeat this subtraction process for each descending power of two.

Example: Convert decimal value 45:

  1. The largest power of two less than 45 is $32$ ($2^5$). Place 1 at bit position 5. Remainder: $45 - 32 = 13$.
  2. The largest power in 13 is $8$ ($2^3$). Place 1 at bit position 3. Remainder: $13 - 8 = 5$.
  3. The largest power in 5 is $4$ ($2^2$). Place 1 at bit position 2. Remainder: $5 - 4 = 1$.
  4. The remaining value is $1$ ($2^0$). Place 1 at bit position 0.

Bit positions 5, 3, 2, and 0 are 1. All other bit positions are 0. The binary result is $101101_2$.

Decimal to Hexadecimal Conversion

Apply repeated division using divisor 16. Record remainders from 0 to 15, representing remainders 10 through 15 using hexadecimal characters A through F.

Example: Convert decimal value 1274 to hexadecimal:

  • $1274 \div 16 = 79$ with remainder $10$ ($\mathtt{A}$)
  • $79 \div 16 = 4$ with remainder $15$ ($\mathtt{F}$)
  • $4 \div 16 = 0$ with remainder $4$ ($\mathtt{4}$)

Read the remainders from bottom to top: $1274_{10} = \mathtt{0x4FA}$.

Binary to Hexadecimal Conversion

Because $16 = 2^4$, each hexadecimal character represents exactly four binary bits.

To convert a binary number to hexadecimal:

  1. Divide the binary bit string into 4-bit groups starting from the least significant bit (right to left).
  2. If the most significant group contains fewer than four bits, add leading zeros.
  3. Replace each 4-bit group with its corresponding hexadecimal character.

Example 1: Convert binary $101101110010_2$:

  1011    0111    0010
    B       7       2

Result: $\mathtt{0xB72}$

Example 2: Convert binary $1011011100_2$ with zero-padding:

  0010    1101    1100
    2       D       C

Result: $\mathtt{0x2DC}$

Caution: Always align 4-bit boundaries starting from the right (LSB). Grouping from the left corrupts the numerical value.

Hexadecimal to Binary Conversion

To convert from hexadecimal to binary, replace each hexadecimal character with its 4-bit binary equivalent.

Example: Convert hexadecimal $\mathtt{0xCAFE}$ to binary:

Hexadecimal Character C A F E
4-bit Binary Field 1100 1010 1111 1110

Result: $1100,1010,1111,1110_2$

Binary to Octal Conversion

Because $8 = 2^3$, each octal digit represents three binary bits. Group the binary string into 3-bit segments starting from the right.

Example: Convert binary $10110111_2$:

  010     110     111
   2       6       7

Result: $267_8$ (or 0o267)

Hexadecimal to Decimal Conversion

Multiply each hexadecimal character by its positional weight ($16^i$) and sum the terms.

Example: Convert $\mathtt{0x1A3C}$ to decimal:

$$\text{Value} = 1 \times 16^3 + 10 \times 16^2 + 3 \times 16^1 + 12 \times 16^0$$ $$\text{Value} = 1 \times 4096 + 10 \times 256 + 3 \times 16 + 12 \times 1 = 6716_{10}$$

Conversion Methods Summary

Source Base Target Base Mathematical Procedure
Decimal Binary Divide repeatedly by 2; read remainders from bottom to top
Decimal Hexadecimal Divide repeatedly by 16; read remainders from bottom to top
Binary Decimal Calculate sum of active bit weights ($\sum b_i \cdot 2^i$)
Binary Hexadecimal Group bits into 4-bit nibbles from right; replace with hex digits
Binary Octal Group bits into 3-bit fields from right; replace with octal digits
Hexadecimal Binary Expand each hex character into a 4-bit binary group
Octal Binary Expand each octal character into a 3-bit binary group
Hexadecimal Decimal Calculate sum of digit weights ($\sum d_i \cdot 16^i$)

Practice Exercise

Convert decimal value 200 to binary and hexadecimal.

View Solution
  1. Repeated division by 2:

    • $200 \div 2 = 100$ remainder 0 (LSB)
    • $100 \div 2 = 50$ remainder 0
    • $50 \div 2 = 25$ remainder 0
    • $25 \div 2 = 12$ remainder 1
    • $12 \div 2 = 6$ remainder 0
    • $6 \div 2 = 3$ remainder 0
    • $3 \div 2 = 1$ remainder 1
    • $1 \div 2 = 0$ remainder 1 (MSB)

    Reading upward gives $11001000_2$.

  2. Subtraction of powers of two:

    • $200 - 128 = 72$ (Bit 7 = 1)
    • $72 - 64 = 8$ (Bit 6 = 1)
    • $8 - 8 = 0$ (Bit 3 = 1)

    Binary value: $11001000_2$.

  3. Hexadecimal conversion: Group binary $11001000_2$ into 4-bit fields: 1100 1000 evaluates to $\mathtt{0xC8}$.

← Binary, Octal, and Hexadecimal Number Systems Negative Numbers in Hardware: Two's Complement →