Unit 1: Data Representation 1.1 Verified

Number systems

8 learning objectives

1. Overview

Number systems are fundamental to computer science because they are used to represent all data and instructions within a computer. Understanding how different number systems work (binary, denary, hexadecimal) and how to convert between them is essential for comprehending how computers store and process information. This topic forms the basis for understanding more complex computer concepts.

Key Definitions

  • Denary (Decimal): A number system with base 10, using digits 0-9. This is the number system humans commonly use.
  • Binary: A number system with base 2, using digits 0 and 1. It is the language of computers because it can represent the on and off states of electronic circuits.
  • Hexadecimal: A number system with base 16, using digits 0-9 and letters A-F (A=10, B=11, C=12, D=13, E=14, F=15).
  • Bit: A single binary digit (0 or 1).
  • Byte: A group of 8 bits.
  • Most Significant Bit (MSB): The leftmost bit in a binary number. In two's complement, it represents the sign (0 for positive, 1 for negative).
  • Overflow: When the result of a calculation is too large to be stored in the available number of bits.
  • Logical Shift: An operation that moves bits to the left or right within a binary number.
  • Two's Complement: A method for representing both positive and negative integers in binary.

Core Content

  • Why Computers Use Binary:
    • Computers are made of electronic circuits.
    • These circuits have two states: ON (represented by 1) and OFF (represented by 0).
    • Binary directly corresponds to these states, making it the simplest and most reliable way for computers to represent data.
Circuit diagram showing ON state (switch closed, bulb lit) representing binary 1, and OFF state (switch open, bulb off) representing binary 0
Binary states represented as electrical circuits
  • Denary, Binary and Hexadecimal:

    Number System Base Digits Used
    Denary 10 0, 1, 2, 3, 4, 5, 6, 7, 8, 9
    Binary 2 0, 1
    Hexadecimal 16 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F
  • Converting Between Number Systems (Up to 255 Denary/FF Hex/11111111 Binary):

    • Denary to Binary: Repeatedly divide the denary number by 2, noting the remainders. The remainders, read in reverse order, form the binary number.
      • Example: Convert 45 to binary:
        • 45 / 2 = 22 remainder 1
        • 22 / 2 = 11 remainder 0
        • 11 / 2 = 5 remainder 1
        • 5 / 2 = 2 remainder 1
        • 2 / 2 = 1 remainder 0
        • 1 / 2 = 0 remainder 1
        • Binary = 101101
    • Binary to Denary: Multiply each binary digit by its corresponding power of 2 (starting from 20 on the right) and add the results.
      • Example: Convert 101101 to denary:
        • (1 x 25) + (0 x 24) + (1 x 23) + (1 x 22) + (0 x 21) + (1 x 20) = 32 + 0 + 8 + 4 + 0 + 1 = 45
    • Denary to Hexadecimal: Repeatedly divide the denary number by 16, noting the remainders. Convert any remainders 10-15 to their hexadecimal equivalent (A-F). The remainders, read in reverse order, form the hexadecimal number.
      • Example: Convert 170 to hexadecimal:
        • 170 / 16 = 10 remainder 10 (A)
        • 10 / 16 = 0 remainder 10 (A)
        • Hexadecimal = AA
    • Hexadecimal to Denary: Multiply each hexadecimal digit by its corresponding power of 16 (starting from 160 on the right) and add the results. Remember that A=10, B=11, etc.
      • Example: Convert AA to denary:
        • (10 x 161) + (10 x 160) = 160 + 10 = 170
    • Binary to Hexadecimal: Group the binary digits into groups of 4 (starting from the right). Convert each group of 4 binary digits into its hexadecimal equivalent.
      • Example: Convert 10110111 to hexadecimal:
        • 1011 0111 = B7 (1011 = 11 = B, 0111 = 7)
    • Hexadecimal to Binary: Convert each hexadecimal digit into its 4-bit binary equivalent.
      • Example: Convert B7 to binary:
        • B = 1011, 7 = 0111, Binary = 10110111
  • Why Hexadecimal is Used:

    • More Compact: Hexadecimal represents binary data more compactly. Each hexadecimal digit represents 4 bits, making it shorter and easier to write.
    • Easier to Read and Remember: Hexadecimal is easier for humans to read and remember than long strings of binary.
    • Applications:
      • MAC addresses: Used to identify network devices.
      • IP addresses: Used to locate devices on a network.
      • HTML color codes: Used to specify colors in web pages (e.g., #FF0000 for red).
      • Assembly language: Used to write low-level programs.
      • Error codes: Used to indicate specific errors in software or hardware.
  • Adding Two Positive 8-bit Binary Integers:

    • Add the binary numbers column by column, starting from the rightmost bit.
    • If the sum of a column is 0 or 1, write it down.
    • If the sum is 2 (1+1), write down 0 and carry-over 1 to the next column.
    • If the sum is 3 (1+1+1), write down 1 and carry-over 1 to the next column.
    • Example: 01101001 + 00010110
       01101001
     + 00010110
     ----------
       01111111
    
  • Overflow:

    • Overflow occurs when the result of an addition is greater than the maximum value that can be stored in the given number of bits.
    • For 8-bit binary numbers, the maximum value is 255 (11111111).
    • Example: 11110000 + 00010000 = 100000000. Since we only have 8 bits, the leftmost '1' is lost, resulting in 00000000. Overflow has occurred.
Diagram showing 8-bit number range from 0 to 255, with overflow occurring when adding 1 to 255, wrapping back to 0
Overflow: when a calculation exceeds the maximum value
  • Logical Binary Shifts:

    • Left Shift: Moves all bits to the left by a specified number of positions. Zeros are added to the rightmost positions. Each left shift effectively multiplies the number by 2.
      • Example: 00110011 left shifted by 2 positions becomes 11001100. (51 becomes 204)
    • Right Shift: Moves all bits to the right by a specified number of positions. Zeros are added to the leftmost positions. Each right shift effectively divides the number by 2 (integer division - any remainder is discarded).
      • Example: 00110011 right shifted by 2 positions becomes 00001100. (51 becomes 12)
  • Two's Complement:

    • Used to represent both positive and negative numbers in binary.
    • For 8-bit integers, the range is -128 to +127.
    • The MSB indicates the sign: 0 = positive, 1 = negative.
    • To find the two's complement (negative) of a number:
      1. Invert all the bits (change 0s to 1s and 1s to 0s).
      2. Add 1 to the result.
    • Example: Find the two's complement of 00000110 (+6)
      1. Invert the bits: 11111001
      2. Add 1: 11111010 (-6)

Exam Focus

  • Number System Conversions: You must be able to convert between denary, binary, and hexadecimal accurately and efficiently. Practice these conversions regularly. Show your working clearly.
  • Why Binary: Examiners are looking for a technical explanation of why computers use binary, not just "because computers understand it." Explain the relationship between binary and the electronic components of a computer.
  • Hexadecimal Advantages: You need to know specific reasons why hexadecimal is beneficial (compact, easier to read). Be prepared to give examples of its use in computing.
  • Binary Addition & Overflow: Clearly show your working for binary addition. Understand the concept of carry-over bits. Be able to explain what overflow is and why it occurs.
  • Shifting: Know the effect of left and right logical shifts on a binary number, specifically multiplication and integer division by 2.
  • Two's complement: Show each step clearly, when inverting bits and adding 1.
  • Terminology: Use technical terms correctly: bit, byte, MSB, overflow, logical shift, two's complement.

Common Mistakes to Avoid

  • ❌ Wrong: Converting to denary instead of hexadecimal when the question asks for a hexadecimal answer. ✓ Right: Carefully read the question and make sure you are converting to the correct base.
  • ❌ Wrong: Treating a hexadecimal '15' as if it were the denary value fifteen. ✓ Right: Remember that in hexadecimal, '15' represents the values '1' and '5' individually, not the quantity fifteen. If you want to represent fifteen as a single digit, use 'F'.
  • ❌ Wrong: Ticking multiple boxes when asked to select only one answer. ✓ Right: Always read the instructions carefully and follow them precisely.
  • ❌ Wrong: Explaining that computers use binary because "it's what the computer understands." ✓ Right: Explain that computers use binary because electronic circuits have two states (on/off) that can directly represent 0 and 1, leading to simpler and more reliable processing.
  • ❌ Wrong: Forgetting to invert all the bits when calculating Two's Complement. ✓ Right: Remember to invert every bit (0 to 1 and 1 to 0) before adding 1.

Exam Tips

  • Practice, Practice, Practice: The more you practice converting between number systems, the faster and more accurate you will become. Use online conversion tools to check your answers.
  • Show Your Working: Even if you get the final answer wrong, you may still get partial credit if you show your working clearly. Examiners want to see your thought process.
  • Read Questions Carefully: Pay close attention to what the question is asking. Make sure you understand what number system you are converting to, what operation you are performing, and what the question is asking you to explain.
  • Allocate Time Wisely: Don't spend too much time on any one question. If you are stuck, move on and come back to it later. Ensure you allocate appropriate time to the number system questions as they are a guaranteed part of the exam.

Test Your Knowledge

Ready to check what you've learned? Practice with 10 flashcards covering key definitions and concepts from Number systems.

Study Flashcards