Computer Science · Ch 2 — Encoding Schemes and Number System
Conversion from other Number Systems to Decimal Number System
Conversion from other Number Systems to Decimal Number System
The reverse journey — from binary, octal or hexadecimal back to decimal — uses the positional-value idea from Section 2.2. The same four steps work for any base value b (2 for binary, 8 for octal, 16 for hexadecimal).
The positional-value method
- Step 1: Write the position number for each alphanumeric symbol in the given number (right-most integer symbol = position 0, increasing leftwards).
- Step 2: Get the positional value of each symbol by raising the base b to its position number.
- Step 3: Multiply each digit by its positional value.
- Step 4: Add all these products — the sum is the equivalent decimal number.
(A) Binary number to decimal number
Binary has base 2, so positional values are powers of 2.
Example 2.6 — Convert (1101)2 to decimal.
Digit : 1 1 0 1
Position number : 3 2 1 0
Positional value : 2^3 2^2 2^1 2^0
1 x 2^3 + 1 x 2^2 + 0 x 2^1 + 1 x 2^0
= 8 + 4 + 0 + 1
= (13)10
Add the product of each positional value with its digit — that sum is the decimal number.
Why are 3 bits grouped together to get an octal number?
The base of octal is 8, and 8 = 2^3 — so three binary digits are exactly enough to represent all 8 octal digits. Put simply, three bits have 2 × 2 × 2 = 8 possible combinations, one for each octal digit. That is why binary numbers are cut into 3-bit groups when converting to octal (Section 2.3.3).
(B) Octal number to decimal number
Same steps with base value 8.
Example 2.7 — Convert (257)8 to decimal.
Digit : 2 5 7
Position number : 2 1 0
Positional value : 8^2 8^1 8^0
2 x 8^2 + 5 x 8^1 + 7 x 8^0
= 128 + 40 + 7
= (175)10
(C) Hexadecimal number to decimal number
Same steps with base value 16 — with one extra care: replace each letter symbol by its decimal equivalent (A = 10, B = 11, C = 12, D = 13, E = 14, F = 15) before multiplying. …