Lesson 1 +30 XP

Number Systems, Base Conversion & Binary Arithmetic

Number Systems, Base Conversion & Binary Arithmetic

A digital computer stores and processes everything as patterns of two voltage levels, written 0 and 1. To reason about these patterns we need number systems other than decimal: binary (base 2) for the hardware itself, and octal (base 8) and hexadecimal (base 16) as short ways of writing long binary strings. This lesson covers positional notation, every conversion asked in IPU papers, and arithmetic in these bases.

1. Positional Number Systems

In a positional (weighted) number system with base or radix r:

  • there are exactly r digits: 0, 1, ldots, r - 1;
  • each position has a weight that is a power of r;
  • the value is the sum of each digit times its weight.

A number with n integer digits and m fraction digits

(an-1 an-2 ldots a1 a0 . a-1 a-2 ldots a-m)r

has the decimal value

N = ∑i=-mn-1 ai ri = an-1 rn-1 + ·s + a1 r + a0 + a-1 r-1 + ·s + a-m r-m

Positional weights of a binary numberPositional weights of a binary number

SystemBase rDigitsExample
Binary20, 1(1101.101)2
Octal80 to 7(725.3)8
Decimal100 to 9(469.375)10
Hexadecimal160 to 9, A to F(3A7.C)16

The leftmost bit of a binary number is the most significant bit (MSB); the rightmost is the least significant bit (LSB). A group of 4 bits is a nibble and 8 bits is a byte.

The first 16 numbers in each base

DecimalBinaryOctalHexDecimalBinaryOctalHex
000000081000108
100011191001119
200102210101012A
300113311101113B
401004412110014C
501015513110115D
601106614111016E
701117715111117F
💡 Tip

Learn this table by heart. Every octal and hex conversion in the exam is just a lookup in it.

2. Any Base to Decimal

Multiply each digit by its weight and add (the formula above).

SolvedExample 1 · Binary, octal and hex to decimal

Convert (1101.101)2, (725.3)8 and (3A7.C)16 to decimal.

  1. (1101.101)2 = 1 · 8 + 1 · 4 + 0 · 2 + 1 · 1 + 1 · tfrac{1}{2} + 0 · tfrac{1}{4} + 1 · tfrac{1}{8} = 13.625
  2. (725.3)8 = 7 · 64 + 2 · 8 + 5 + 3 · tfrac{1}{8} = 448 + 16 + 5 + 0.375 = 469.375
  3. (3A7.C)16 = 3 · 256 + 10 · 16 + 7 + 12 · tfrac{1}{16} = 768 + 160 + 7 + 0.75 = 935.75
Answer13.625, 469.375 and 935.75

The same rule works for any base, for example (245)6 = 2 · 36 + 4 · 6 + 5 = (101)10.

3. Decimal to Any Base

The integer part and the fraction part are converted separately.

  • Integer part: repeated division by r. Divide by r, write down the remainder, and keep dividing the quotient until it becomes 0. The remainders read bottom to top (last remainder first) give the digits.
  • Fraction part: repeated multiplication by r. Multiply the fraction by r; the integer part of the product is the next digit. Continue with the new fraction until it becomes 0 or enough digits are found. The digits read top to bottom.

Repeated division and multiplication for 156.6875Repeated division and multiplication for 156.6875

SolvedExample 2 · Decimal to binary, octal and hex

Convert (156.6875)10 to binary, octal and hexadecimal.

Integer 156 to binary: 156/2 = 78 r 0, 78/2 = 39 r 0, 39/2 = 19 r 1, 19/2 = 9 r 1, 9/2 = 4 r 1, 4/2 = 2 r 0, 2/2 = 1 r 0, 1/2 = 0 r 1. Reading upward: 10011100.

Fraction 0.6875 to binary: 0.6875 × 2 = 1.375, 0.375 × 2 = 0.75, 0.75 × 2 = 1.5, 0.5 × 2 = 1.0. Reading downward: .1011.

Octal: 156/8 = 19 r 4, 19/8 = 2 r 3, 2/8 = 0 r 2, so 234; 0.6875 × 8 = 5.5, 0.5 × 8 = 4.0, so .54.

Hex: 156/16 = 9 r 12 (C), 9/16 = 0 r 9, so 9C; 0.6875 × 16 = 11.0, so .B.

Answer(10011100.1011)2 = (234.54)8 = (9C.B)16

Fractions that never end

A decimal fraction can be exact in base 10 and endless in base 2. Converting 0.1:

StepFraction × 2Bit
10.20
20.40
30.80
41.61
51.21
60.40
70.80
81.61

The pattern 0011 repeats forever: (0.1)10 = (0.0overline{0011})2 = 0.000110011ldots This is why 0.1 + 0.2 is not exactly 0.3 in floating point: the stored value is rounded. In an exam, stop after the number of places asked (usually 4 to 6) and say "approximately".

4. Binary, Octal and Hex Shortcuts

Because 8 = 23 and 16 = 24, each octal digit is exactly 3 bits and each hex digit is exactly 4 bits. No arithmetic is needed:

  • Binary to octal / hex: starting at the binary point, group bits in 3s (octal) or 4s (hex), going left for the integer part and right for the fraction. Pad the ends with zeros and replace each group by its digit.
  • Octal / hex to binary: replace every digit by its 3-bit or 4-bit pattern.
  • Octal to hex (or back): go through binary.
SolvedExample 3 · Grouping bits

Convert (1011011110.01101)2 to octal and hexadecimal, and (5736)8 to hexadecimal.

  1. Octal groups: 001 011 011 110 . 011 010 ⇒ (1336.32)8
  2. Hex groups: 0010 1101 1110 . 0110 1000 ⇒ (2DE.68)16
  3. (5736)8 = 101 111 011 110 = 1011 1101 1110 = (BDE)16
Answer(1336.32)8, (2DE.68)16 and (BDE)16

Always group outward from the binary point. Grouping the fraction from the right end gives a wrong answer: .01101 must become .0110 1000, not .0000 1101.

5. Finding an Unknown Base

SolvedExample 4 · Solve for the base

Find the base b if (121)b = (144)8.

  1. Right side: (144)8 = 64 + 32 + 4 = 100.
  2. Left side: (121)b = b2 + 2b + 1 = (b + 1)2.
  3. (b + 1)2 = 100 gives b + 1 = 10, so b = 9 (the negative root is not a base).
  4. Check: digit 2 is allowed in base 9.
Answerb = 9

6. Binary Arithmetic

Addition

ABCarry-inSumCarry-out
00000
01010
11001
11111

In short: 1 + 1 = 10 (write 0, carry 1) and 1 + 1 + 1 = 11 (write 1, carry 1).

Subtraction

0 - 0 = 0, 1 - 0 = 1, 1 - 1 = 0, and 0 - 1 = 1 with a borrow of 1 from the next column (because 10 - 1 = 1). Computers do not subtract this way; they add the complement (next lesson).

Multiplication and division

Binary multiplication is shift-and-add: each bit of the multiplier is 0 (add nothing) or 1 (add the multiplicand, shifted). Division is shift-and-subtract, and each quotient bit is 1 if the divisor fits, else 0.

SolvedExample 5 · The four operations

Compute 10110 + 01101, 11010 - 01101, 1011 × 101 and 110111 ÷ 101.

  1. Add: 10110 + 01101 = 100011 (check: 22 + 13 = 35).
  2. Subtract: 11010 - 01101 = 01101 (check: 26 - 13 = 13).
  3. Multiply: partial products 1011, 0000 (shifted 1), 1011 (shifted 2); sum = 110111 (check: 11 × 5 = 55).
  4. Divide: 110111 ÷ 101 = 1011, remainder 0 (check: 55 ÷ 5 = 11).
Answer100011, 01101, 110111 and 1011

The multiplication laid out in columns:

TEXT
        1 0 1 1      multiplicand (11)
      x   1 0 1      multiplier   (5)
      ---------
        1 0 1 1      bit 0 = 1: add multiplicand
      0 0 0 0        bit 1 = 0: add zero, shifted left 1
    1 0 1 1          bit 2 = 1: add multiplicand, shifted left 2
    -----------
    1 1 0 1 1 1      product (55)

Octal and hexadecimal addition

Add digit by digit in decimal. If the column sum reaches the base, subtract the base and carry 1.

SolvedExample 6 · Hex and octal sums

Add (3AF)16 + (1C9)16 and (765)8 + (243)8.

  1. Hex, right column: F + 9 = 15 + 9 = 24 = 16 + 8, write 8, carry 1.
  2. Middle: A + C + 1 = 10 + 12 + 1 = 23 = 16 + 7, write 7, carry 1.
  3. Left: 3 + 1 + 1 = 5. Result (578)16 (check: 943 + 457 = 1400).
  4. Octal: 5 + 3 = 8 = 8 + 0, write 0 carry 1; 6 + 4 + 1 = 11 = 8 + 3, write 3 carry 1; 7 + 2 + 1 = 10 = 8 + 2, write 2 carry 1. Result (1230)8 (check: 501 + 163 = 664).
Answer(578)16 and (1230)8

7. Range of n Bits

With n bits there are 2n different patterns, so an unsigned n-bit number covers 0 to 2n - 1:

BitsPatternsUnsigned range
4160 to 15
82560 to 255
1010240 to 1023
1665,5360 to 65,535
32about 4.29 × 1090 to 4,294,967,295

To find how many bits a decimal number N needs, use n = ⌈ log2 (N + 1) ⌉. For example 2023 needs 11 bits, since 210 = 1024 ≤ 2023 < 2048 = 211: (2023)10 = (11111100111)2 = (3747)8 = (7E7)16.

💡 Tip

Key points to remember

  • Value = ∑ ai ri; this converts any base to decimal.
  • Decimal to base r: integer by repeated division (remainders read upward), fraction by repeated multiplication (integer parts read downward).
  • Octal digit = 3 bits, hex digit = 4 bits; group outward from the point.
  • Some decimal fractions such as 0.1 never end in binary.
  • n bits give 2n patterns, unsigned range 0 to 2n - 1.
🎯 END-TERM EXAM PREP

📝 IPU End-Term Exam Corner (5-10 Marks)

  • Q1. Convert (156.6875)10 into binary, octal and hexadecimal. Show all steps. (5 Marks)
  • Write: the division ladder for 156, the multiplication ladder for 0.6875, then octal and hex either directly or by grouping the binary result.
  • Q2. Convert (3A7.C)16 to decimal and octal. (2.5 Marks)
  • Write: the weighted sum (935.75), then hex to binary to octal: 0011 1010 0111.1100 = 1647.68.
  • Q3. Find the base b if (121)b = (144)8. (2.5 Marks)
  • Q4. Perform in binary: 1011 × 1101 and 110111 ÷ 101. Verify in decimal. (5 Marks)
  • Write: 1011 × 1101 = 10001111 (11 × 13 = 143) with all partial products, and the long division.
  • Q5. Why can (0.1)10 not be represented exactly in binary? (2.5 Marks)