Home / Notes / Class 9 / Computer Science / Number systems

Number systems: Class 9 Computer Science

Written by Usman Tariq (Computer Science)

Decimal, binary, octal and hexadecimal number systems, conversion between them, binary addition, complements, and how computers store characters using ASCII and Unicode, with worked examples.

Key points

A number system is a way of writing numbers using a fixed set of symbols called digits. The base (or radix) of a system is the number of different digits it uses. Each digit has a value that depends on its place, so these are called positional number systems.

The four number systems used in computing are:

  • Decimal: base 10, digits 0 to 9. This is the system we use daily.
  • Binary: base 2, digits 0 and 1. This is the language of the computer.
  • Octal: base 8, digits 0 to 7.
  • Hexadecimal: base 16, digits 0 to 9 and letters A to F, where A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.

Computers use binary because electronic circuits have two clear states: on and off (or high and low voltage). These two states are easy to build, store and detect, and they are less likely to be misread than ten different levels. One binary digit is called a bit. Four bits make a nibble and eight bits make a byte.

In any positional system the value of a digit is the digit multiplied by the base raised to the power of its position. Positions are counted from the right, starting at 0. For example, in the decimal number 352, the value is 3 × 10² + 5 × 10¹ + 2 × 10⁰ = 300 + 50 + 2.

Binary to decimal: multiply each bit by 2 raised to its position and add the results. Example: 1011 in binary.

  • 1 × 2³ = 8
  • 0 × 2² = 0
  • 1 × 2¹ = 2
  • 1 × 2⁰ = 1
  • Total = 8 + 0 + 2 + 1 = 11, so (1011)₂ = (11)₁₀.

Decimal to binary: divide the number by 2 again and again and write the remainders. Read the remainders from bottom to top. Example: 13.

  • 13 ÷ 2 = 6 remainder 1
  • 6 ÷ 2 = 3 remainder 0
  • 3 ÷ 2 = 1 remainder 1
  • 1 ÷ 2 = 0 remainder 1
  • Reading upward gives 1101, so (13)₁₀ = (1101)₂.

The same division method works for other bases. To convert a decimal number to octal divide by 8, and to hexadecimal divide by 16. Write the remainders from bottom to top, using letters A to F for remainders 10 to 15.

Binary, octal and hexadecimal are linked by grouping bits:

  • Binary to octal: group the bits in threes from the right. Each group becomes one octal digit.
  • Binary to hexadecimal: group the bits in fours from the right. Each group becomes one hex digit.
  • To go back, replace each octal digit by 3 bits or each hex digit by 4 bits.
  • Example: 11010110 grouped as 1101 0110 gives D6 in hex.

Hexadecimal is popular because it is a short way to write long binary numbers. One hex digit stands for exactly four bits, so a byte is just two hex digits. It is used for colour codes in web pages, memory addresses and MAC addresses.

Binary addition follows four rules:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 1 = 10 (write 0, carry 1)
  • 1 + 1 + 1 = 11 (write 1, carry 1)

Negative numbers can be shown using complements. The 1's complement is found by changing every 0 to 1 and every 1 to 0. The 2's complement is the 1's complement plus 1. Computers use 2's complement to store negative integers and to do subtraction by addition.

Computers also store letters and symbols as numbers. ASCII (American Standard Code for Information Interchange) uses 7 bits to represent 128 characters, for example capital A has the code 65 and a has 97. Extended ASCII uses 8 bits for 256 characters. Unicode uses more bits and can represent characters of many languages including Urdu.

Study tip: Practise conversions every day because they carry sure marks. Always show the division steps or the power of 2 steps, and check the answer by converting back. Memorise the powers of 2 up to 2⁸ (1, 2, 4, 8, 16, 32, 64, 128, 256) and the hex letters, which will make working fast.

Definitions and flashcards

Say the meaning first, then open the card to check.

Base

The number of different digits in a number system.

Bit

A binary digit, 0 or 1.

Byte

A group of 8 bits.

Binary

The base 2 number system using 0 and 1.

Hexadecimal

The base 16 system using 0 to 9 and A to F.

Octal

The base 8 system using digits 0 to 7.

1's complement

A binary number with every bit flipped.

ASCII

A code that gives each character a number, using 7 bits for 128 characters.

Unicode

A character code that covers the writing systems of many languages.

Formula sheet

NameFormulaWhat it means
Value of a digitdigit × base^positionPosition is counted from the right starting at 0
Binary to decimald₃ × 2³ + d₂ × 2² + d₁ × 2¹ + d₀ × 2⁰Add the weighted bits
2's complement1's complement + 1Used to represent negative numbers
Characters in n bits2ⁿ7 bits give 128, 8 bits give 256

Short questions with model answers

These are the kind of questions asked for 2, 3 and 5 marks. Try each one before opening the answer.

Why do computers use the binary number system? (3 marks)

Computer circuits have two stable states, on and off, which match the digits 1 and 0. Two states are simple and cheap to build and are reliable because they are hard to confuse. Because of this all data is stored and processed in binary.

Define base of a number system and give the base of binary, octal and hexadecimal. (2 marks)

The base is the number of different digits a number system uses. Binary has base 2, octal has base 8 and hexadecimal has base 16.

Write the hexadecimal digits that stand for the decimal values 10 to 15. (2 marks)

10 = A, 11 = B, 12 = C, 13 = D, 14 = E and 15 = F.

Explain how a binary number is converted to hexadecimal. (5 marks)

Start from the right and make groups of four bits. If the last group has fewer than four bits, add zeros on the left. Write the hex digit for each group using its value from 0 to 15, with A to F for 10 to 15. Joining these digits gives the hexadecimal number. For example, 1010 1111 becomes AF.

What is ASCII? How many characters can it represent? (3 marks)

ASCII is a standard code that assigns a number to each letter, digit and symbol so that computers can store and exchange text. Standard ASCII uses 7 bits and can represent 128 characters. Extended ASCII uses 8 bits and represents 256.

Find the 1's complement and 2's complement of 10110. (3 marks)

The 1's complement is found by flipping each bit, so 10110 becomes 01001. The 2's complement is 01001 + 1 = 01010.

Numericals with worked steps

Convert (45)₁₀ to binary.
  1. 45 ÷ 2 = 22 remainder 1
  2. 22 ÷ 2 = 11 remainder 0
  3. 11 ÷ 2 = 5 remainder 1
  4. 5 ÷ 2 = 2 remainder 1
  5. 2 ÷ 2 = 1 remainder 0
  6. 1 ÷ 2 = 0 remainder 1
  7. Read remainders from bottom to top: 101101
  8. Check: 32 + 8 + 4 + 1 = 45

Answer: (101101)₂

Convert (11011)₂ to decimal.
  1. 1 × 2⁴ = 16
  2. 1 × 2³ = 8
  3. 0 × 2² = 0
  4. 1 × 2¹ = 2
  5. 1 × 2⁰ = 1
  6. Sum = 16 + 8 + 0 + 2 + 1 = 27

Answer: (27)₁₀

Convert (10110110)₂ to hexadecimal.
  1. Group in fours: 1011 and 0110
  2. 1011 = 8 + 2 + 1 = 11 = B
  3. 0110 = 4 + 2 = 6
  4. Join the digits: B6
  5. Check: 11 × 16 + 6 = 182, and 128 + 32 + 16 + 4 + 2 = 182

Answer: (B6)₁₆

Add the binary numbers 1101 and 1011.
  1. Rightmost bit: 1 + 1 = 10, write 0, carry 1
  2. Next: 0 + 1 + carry 1 = 10, write 0, carry 1
  3. Next: 1 + 0 + carry 1 = 10, write 0, carry 1
  4. Next: 1 + 1 + carry 1 = 11, write 1, carry 1
  5. Write the last carry: 1
  6. Result = 11000
  7. Check: 13 + 11 = 24 and 11000 = 16 + 8 = 24

Answer: (11000)₂

Convert (2F)₁₆ to decimal.
  1. F = 15
  2. 2 × 16¹ = 32
  3. 15 × 16⁰ = 15
  4. Total = 32 + 15 = 47

Answer: (47)₁₀

Common mistakes

  • Reading the remainders from top to bottom in decimal to binary conversion. They must be read from bottom to top.
  • Starting the position count at 1 instead of 0. The rightmost digit has power 0.
  • Grouping bits from the left. Groups of 3 or 4 bits must start from the right side.
  • Forgetting the carry in binary addition, especially 1 + 1 + 1.
  • Writing hex letters wrongly, for example taking B as 12. B is 11, and C is 12.

Practise this chapter

Practice questions and timed test Printable worksheet

Previous: Software Next: Networks and the internet