Free tutorials & notes in Hindi & English · Clean code examples 🧰 Free PDF & Image Tools →
🖥️ Unit 1 – Computer Systems & Organisation  ·  Lesson 05

Number System Conversions

Conversion map

There are only two big methods. To go from decimal to another base, divide repeatedly. To come to decimal, multiply by place values and add. Between binary, octal and hex we use quick grouping shortcuts.

Decimalbase 10÷ 2Binarybase 2group bitsOctal / Hexbase 8 / 16
Decimal → others: repeated division · Others → decimal: place values · Binary ↔ octal/hex: groups of 3 / 4

Decimal → binary, octal or hexadecimal

Rule: divide the decimal number by the new base, write the remainder, divide the quotient again, and continue until the quotient is 0. Read remainders from bottom to top.

Example 1: (156)₁₀ → binary

DivideQuotientRemainder
156 ÷ 2780
78 ÷ 2390
39 ÷ 2191
19 ÷ 291
9 ÷ 241
4 ÷ 220
2 ÷ 210
1 ÷ 201
Read the remainders upward: (156)₁₀ = (10011100)₂

Example 2: (156)₁₀ → octal

156 ÷ 8 = 19 remainder 4; 19 ÷ 8 = 2 remainder 3; 2 ÷ 8 = 0 remainder 2. Upward: (234)₈.

Example 3: (156)₁₀ → hexadecimal

156 ÷ 16 = 9 remainder 12 = C; 9 ÷ 16 = 0 remainder 9. Upward: (9C)₁₆.

⚠️ Common mistake

In hex, a remainder of 10–15 must be written as a letter A–F, not as two digits. Writing 156 as "912" is wrong; it is 9C.

Any base → decimal

Rule: multiply each digit by baseposition (position 0 at the right) and add all results.

NumberExpansionDecimal
(10011100)₂1×128 + 0×64 + 0×32 + 1×16 + 1×8 + 1×4 + 0×2 + 0×1156
(234)₈2×64 + 3×8 + 4×1156
(9C)₁₆9×16 + 12×1156
(1011.1)₂8 + 0 + 2 + 1 + 1×2⁻¹11.5
All three numbers are the same value 156

Digits after a point have negative positions: −1, −2 … So in binary the weights are ½ = 0.5, ¼ = 0.25, ⅛ = 0.125 …

Decimal fractions → binary

Rule: multiply the fractional part by 2. The integer part (0 or 1) is the next bit. Keep only the fraction and repeat. Read bits top to bottom.

StepMultiplyResultBit
10.625 × 21.251
20.25 × 20.50
30.5 × 21.01
40.0 – stop
(0.625)₁₀ = (0.101)₂
Python
x = 0.625
bits = ''
for step in range(4):
    x = x * 2
    bits += str(int(x))      # integer part is the next bit
    x = x - int(x)
print('0.' + bits)
0.1010

So (12.625)₁₀ = (1100.101)₂ — convert the integer part by division and the fraction by multiplication, then join them.

Binary ↔ octal (groups of 3)

Binary → octal: starting from the right, make groups of 3 bits (add 0s on the left if needed) and write each group's value.

10011100 →010011100
Groups of 3 from the right → 2 3 4 → (234)₈

Octal → binary: write each octal digit as 3 bits. (57)₈ → 101 111 → (101111)₂.

Binary ↔ hexadecimal (groups of 4)

Binary → hex: groups of 4 bits from the right. (10011100)₂ → 1001 1100 → 9 C → (9C)₁₆.

1010111111 →001010111111
Add zeros on the left: 0010 1011 1111 → 2 B F → (2BF)₁₆

Hex → binary: each hex digit becomes 4 bits. (A7)₁₆ → 1010 0111 → (10100111)₂.

Octal ↔ hexadecimal

There is no direct shortcut, so use binary in the middle.

(345)₈octal011 100 1013 bits each1110 0101regroup in 4s(E5)₁₆hex
Octal → binary → hexadecimal

Reverse example: (B2)₁₆ → 1011 0010 → regroup 3s: 010 110 010 → (262)₈.

Write your own converter in Python

This program uses the same repeated-division method you do on paper — % gives the remainder, // gives the quotient.

Python
def to_base(n, base):
    digits = '0123456789ABCDEF'
    if n == 0:
        return '0'
    result = ''
    while n > 0:
        result = digits[n % base] + result   # remainder becomes next digit
        n = n // base
    return result

for b in (2, 8, 16):
    print(156, 'in base', b, '=', to_base(156, b))
156 in base 2 = 10011100 156 in base 8 = 234 156 in base 16 = 9C

And the reverse, using the place-value method (Horner's way: multiply the running value by the base and add the next digit):

Python
def to_decimal(text, base):
    digits = '0123456789ABCDEF'
    value = 0
    for ch in text.upper():
        value = value * base + digits.index(ch)
    return value

print(to_decimal('10011100', 2))
print(to_decimal('234', 8))
print(to_decimal('9C', 16))
156 156 156

Summary & practice

  • Decimal → base b: divide by b, remainders upward.
  • Base b → decimal: Σ digit × bposition.
  • Fraction → binary: multiply by 2, integer parts downward.
  • Binary ↔ octal: groups of 3; binary ↔ hex: groups of 4; octal ↔ hex via binary.
✅ Practice

1) (99)₁₀ = (?)₂ 2) (110110)₂ = (?)₁₆ 3) (725)₈ = (?)₁₀ 4) (3F)₁₆ = (?)₈ 5) (0.75)₁₀ = (?)₂

Answers: 1) 1100011 2) 36 3) 469 4) 77 5) 0.11

Frequently Asked Questions

How do I convert decimal to binary quickly?
Divide the number by 2 again and again, writing the remainders. Read the remainders from bottom to top. For example 13 → remainders 1,0,1,1 → 1101.
How do I convert octal to hexadecimal?
Go through binary. Write each octal digit as 3 bits, then regroup the bits in fours from the right and write each group as a hex digit.
Why do we read remainders from bottom to top?
The first remainder is the ones place (least significant digit). Each later remainder is a higher place, so the last remainder is the most significant digit and must be written first.
← Class 11 Computer Science
🔗

Share this topic with a friend

यह topic किसी दोस्त को भेजें

Found it useful? Send it to a classmate learning the same thing.

अच्छा लगा? जो दोस्त यही सीख रहा है, उसे भेज दीजिए।

Next topicEncoding: ASCII, ISCII & Unicode Your progress: 5 / 29 (17%) · Lesson 6 / 29 Continue →

How was this lesson?

Your feedback helps us make the content better.

Write a review or suggestion (optional)

After approval, your name and city may appear publicly with your review. Please do not write your email or phone number.

▶ CodingEasily on YouTube

Learn with video lessons in easy Hindi

Featured video: RDBMS Part 3 – Class XI Commerce IT

▶ Subscribe – it’s free