Skip to content
Sign in

Number Systems Revision Notes: Binary, Octal, Hexadecimal Conversions and Complements

Complete revision notes on number systems for Computer Science teacher exams like BPSC TRE: conversions, binary arithmetic, 1's and 2's complement, with solved examples and exam shortcuts.

CodeOrbit Learn TeamPublished 3 min read

Number systems questions are quick marks in any Computer Science paper, if you know the methods well. These notes cover every conversion, binary arithmetic and complements with solved examples.

The four number systems

System

Base

Digits used

Example

Binary

2

0, 1

1011₂

Octal

8

0–7

17₈

Decimal

10

0–9

25₁₀

Hexadecimal

16

0–9, A–F (A=10 … F=15)

2F₁₆

The value of a digit = digit × base^position, positions counted from 0 at the right.

Any base → Decimal

Multiply each digit by its place value and add.

Example: 1011₂ = 1×2³ + 0×2² + 1×2¹ + 1×2⁰ = 8 + 0 + 2 + 1 = 11₁₀

Example: 2F₁₆ = 2×16 + 15×1 = 47₁₀

Fractions: places after the point use negative powers. 0.101₂ = 1×2⁻¹ + 0×2⁻² + 1×2⁻³ = 0.5 + 0.125 = 0.625₁₀

Decimal → Any base

Integer part: divide repeatedly by the base and read the remainders bottom to top.

Example: 25₁₀ to binary

Division

Quotient

Remainder

25 ÷ 2

12

1

12 ÷ 2

6

0

6 ÷ 2

3

0

3 ÷ 2

1

1

1 ÷ 2

0

1

Reading upward: 11001₂

Fraction part: multiply repeatedly by the base and read the integer parts top to bottom.

Example: 0.375₁₀ to binary: 0.375×2 = 0.75 → 0; 0.75×2 = 1.5 → 1; 0.5×2 = 1.0 → 1. Answer: 0.011₂

Binary ↔ Octal ↔ Hexadecimal (the grouping shortcut)

Because 8 = 2³ and 16 = 2⁴:

  • Binary → Octal: group bits in 3s from the point.
  • Binary → Hex: group bits in 4s from the point.

Example: 1101011₂

  • Octal: 1 | 101 | 011 → 1 5 3 → 153₈
  • Hex: 110 | 1011 → 6 B → 6B₁₆

Octal → Hex: go through binary. 153₈ → 001 101 011 → 1101011 → 6B₁₆

Binary arithmetic

Addition rules: 0+0=0, 0+1=1, 1+1=10 (write 0, carry 1), 1+1+1=11 (write 1, carry 1).

Plain Text
   1 0 1 1   (11)
 + 0 1 1 1   ( 7)
 ---------
 1 0 0 1 0   (18)

Subtraction is usually done with 2's complement (below).

1's and 2's complement

  • 1's complement: flip every bit. 1's complement of 01011 is 10100.
  • 2's complement: 1's complement + 1. 2's complement of 01011 is 10100 + 1 = 10101.

Shortcut for 2's complement: from the right, copy bits up to and including the first 1, then flip the rest. 01011000 → 10101000.

Subtraction using 2's complement

To compute A − B: add A to the 2's complement of B. If there is a carry out, drop it; the result is positive.

Example: 9 − 5 with 4 bits: 1001 + (2's complement of 0101 = 1011) = 1 0100 → drop carry → 0100 = 4 ✔

Range of signed numbers

With n bits in 2's complement, the range is −2n−1-2^{n-1} to 2n−1−12^{n-1} - 1. For 8 bits: −128 to +127.

Codes you should know

Code

Key idea

BCD (8421)

Each decimal digit written as 4 bits: 25 → 0010 0101

Excess-3

BCD + 3 for each digit: 2 → 0101

Gray code

Successive numbers differ in only one bit

ASCII

7-bit character code: 'A' = 65, 'a' = 97, '0' = 48

Binary → Gray: the first bit stays the same; each next Gray bit = XOR of the current and previous binary bits. 1011 → 1, 1⊕0=1, 0⊕1=1, 1⊕1=0 → 1110.

Quick practice

  1. Convert 156₁₀ to hexadecimal.
  2. Convert 3A₁₆ to binary and octal.
  3. Find the 2's complement of 10110100.
  4. What is the range of a 6-bit signed number in 2's complement?

Answers: 1) 9C₁₆ (156 = 9×16 + 12). 2) 0011 1010₂ = 72₈. 3) 01001100. 4) −32 to +31.

Tags:#Computer Science#Number Systems#BPSC TRE#Digital Logic

Frequently asked questions

Why do computers use 2's complement?

It gives a single representation of zero and lets the same adder circuit do both addition and subtraction.

How many bits are needed to store a number N?

The smallest n with 2ⁿ > N. For example, 100 needs 7 bits because 2⁷ = 128.

What is the base of the number system used in BCD?

BCD stores decimal (base-10) digits, each using 4 binary bits.