Computer Architecture
1.2 Number System
Conversions
Understanding
how to convert numbers between decimal,
binary, octal, and hexadecimal systems is a fundamental skill
in computer science. Since computers operate primarily in binary, but humans
are accustomed to decimal, these conversions are crucial for interpreting data,
debugging programs, and working with hardware. This section will guide you through
the various methods of converting numbers from one base to another.
1.2.1 Decimal to Other Number Systems
When
converting a decimal number to another base (binary, octal, or hexadecimal),
the standard method is successive
division for integer parts and successive multiplication for fractional
parts.
Method (Integers – Successive Division)
1. Divide
the decimal number by the target base.
2. Record
the remainder (this becomes a digit in the new base).
3. Divide
the quotient by the target base again.
4. Repeat
steps 2 and 3 until the quotient is 0.
5. Read
the remainders from bottom
to top (last remainder = Most Significant Digit, first
remainder = Least Significant Digit).
Example 1: Convert Decimal 25 to Binary
Target
base = 2
Division |
Quotient |
Remainder |
25 ÷ 2 |
12 |
1 |
12 ÷ 2 |
6 |
0 |
6 ÷ 2 |
3 |
0 |
3 ÷ 2 |
1 |
1 |
1 ÷ 2 |
0 |
1 |
Reading
from bottom to top: 11001₂
So, 25₁₀ = 11001₂
Example 2: Convert Decimal 179 to Hexadecimal
Target
base = 16 (A=10, B=11, …, F=15)
Division |
Quotient |
Remainder |
Hexadecimal |
179 ÷ 16 |
11 |
3 |
3 |
11 ÷ 16 |
0 |
11 |
B |
Reading
from bottom to top: B3₁₆
So, 179₁₀ = B3₁₆
1.2.2 Binary to Other Number Systems
Binary
can be converted to decimal using positional
notation or to octal/hexadecimal using bit grouping.
Method 1: Positional Notation (Binary →
Decimal)
1. Start
from the rightmost digit.
2. Multiply
each digit by 2ⁿ,
where n is its
position (starting from 0).
3. Sum
all the products.
Method 2: Grouping Bits (Binary →
Octal/Hexadecimal)
·
Binary to Octal:
Group digits in sets of 3 (from right to left). Pad with leading zeros if
needed. Convert each group to octal.
·
Binary to Hexadecimal:
Group digits in sets of 4 (from right to left). Pad with leading zeros if
needed. Convert each group to hexadecimal.
Example 1: Convert Binary 10110 to Decimal
Binary:
10110₂
·
0 × 2⁰ = 0
·
1 × 2¹ = 2
·
1 × 2² = 4
·
0 × 2³ = 0
·
1 × 2⁴ = 16
Sum:
0 + 2 + 4 + 0 + 16 = 22
So, 10110₂ = 22₁₀
Example 2: Convert Binary 1101101110 to
Hexadecimal
Binary:
1101101110₂
Group
into fours: 0011 0110 1110
·
0011 → 3
·
0110 → 6
·
1110 → E
Combined:
36E₁₆
So, 1101101110₂ = 36E₁₆
1.2.3 Octal to Other Number Systems
Octal
is easily converted to decimal using positional notation and to binary using
direct digit mapping.
Method 1: Positional Notation (Octal →
Decimal)
1. Start
from the rightmost digit.
2. Multiply
each digit by 8ⁿ,
where n is its
position (starting from 0).
3. Sum
all the products.
Method 2: Direct Conversion (Octal →
Binary)
1. Convert
each octal digit into its 3-bit
binary equivalent.
2. Combine
the groups.
Example 1: Convert Octal 73 to Decimal
·
3 × 8⁰ = 3
·
7 × 8¹ = 56
Sum:
3 + 56 = 59
So, 73₈ = 59₁₀
Example 2: Convert Octal 504 to Binary
·
5 → 101
·
0 → 000
·
4 → 100
Combined:
101000100₂
So, 504₈ = 101000100₂
1.2.4 Hexadecimal to Other Number Systems
Hexadecimal
is commonly converted to decimal via positional notation and to binary via
direct digit mapping (4 bits per digit).
Method 1: Positional Notation (Hex →
Decimal)
1. Start
from the rightmost digit.
2. Multiply
each digit (A=10, B=11, etc.) by 16ⁿ,
where n starts at
0.
3. Sum
all the products.
Method 2: Direct Conversion (Hex →
Binary)
1. Convert
each hexadecimal digit into its 4-bit
binary equivalent.
2. Combine
the groups.
Example 1: Convert Hexadecimal A5 to Decimal
·
5 × 16⁰ = 5
·
A × 16¹ = 10 × 16 = 160
Sum:
5 + 160 = 165
So, A5₁₆ = 165₁₀
Example 2: Convert Hexadecimal 1F8 to Binary
·
1 → 0001
·
F → 1111
·
8 → 1000
Combined:
000111111000₂
So, 1F8₁₆ = 111111000₂