Cambridge O Level2210

Number systems

Computer Science 2210 Chapter Notes

What this chapter covers

Number systemsText, sound and imagesData storage and compression
ShareWhatsAppPost
Number systems notes

Unable to load PDF

The notes viewer could not load. Please refresh the page.

Read online free. Download a watermarked copy with a free account.

Read the notes

The full Number systems notes as text: skim, search, and jump between subtopics.

~12 min read

1. Introduction to Number Systems

In everyday life, we use the denary (or decimal) number system, which is base-10 and uses the digits 0 through 9. Computers, however, operate using millions of tiny electronic switches that can only be in one of two states: on or off. This is represented by the binary number system, a base-2 system using only the digits 1 (on) and 0 (off). Because long strings of binary are difficult for humans to read, the hexadecimal system (base-16) is often used as a more compact, human-friendly way to represent binary data. Hexadecimal uses the digits 0-9 and the letters A-F to represent denary values 0-15.

Key term

Base: The number of unique digits, including zero, used to represent numbers in a positional numeral system.

Fun fact

The term 'bit' is a contraction of 'binary digit'. Eight bits together form a 'byte'.

Worked example 13 marks

Compare the base and the digits used in the Denary, Binary, and Hexadecimal number systems.

  1. 1

    Denary: Base-10. It uses ten digits: 0, 1, 2, 3, 4, 5, 6, 7, 8, 9.

  2. 2

    Binary: Base-2. It uses two digits: 0 and 1.

  3. 3

    Hexadecimal: Base-16. It uses sixteen symbols: the digits 0-9 and the letters A (10), B (11), C (12), D (13), E (14), F (15).

Recap

  • Denary is the base-10 number system we use daily.
  • Computers use binary (base-2) because their circuits have two states: on (1) and off (0).
  • Hexadecimal (base-16) is a compact way for humans to represent binary data.
  • One hexadecimal digit can represent a 4-bit binary number.
  • The symbols A-F in hexadecimal represent the denary values 10-15.

Quick check

  1. Why do computers process data using the binary system?1 mark
  2. What denary value does the hexadecimal digit 'C' represent?1 mark

2. Converting Between Denary and Binary

Converting between denary and binary is a fundamental skill. To convert a denary number to binary, you can use the place value method. Find the largest power of 2 that fits into your number, place a '1' in that column, subtract it from your number, and repeat with the remainder until your number is zero. To convert a binary number to denary, you simply add up the place values (powers of 2) for each position that contains a '1'. An 8-bit binary number has place values: 128, 64, 32, 16, 8, 4, 2, 1.

Denary Value = Σ(digit × 2^position)

Key term

Place Value: The value represented by a digit in a number based on its position within the number (e.g., in binary, the rightmost digit has a place value of 2^0 = 1).

Examiner insight

Examiners look for clear working. When converting, writing out the place value grid (128, 64, 32...) will often gain you method marks even if your final answer has a calculation error.

Common pitfall

When converting from denary to binary, a common mistake is to forget a place value, leading to an incorrect binary string. Using a grid is the safest method.

Worked example 13 marks

Convert the denary number 147 into an 8-bit binary number.

  1. 1

    Start with the place values for 8 bits: 128, 64, 32, 16, 8, 4, 2, 1.

  2. 2

    Does 128 fit into 147? Yes. Place a 1. Remainder: 147 - 128 = 19.

  3. 3

    Does 64 fit into 19? No. Place a 0.

  4. 4

    Does 32 fit into 19? No. Place a 0.

  5. 5

    Does 16 fit into 19? Yes. Place a 1. Remainder: 19 - 16 = 3.

  6. 6

    Does 8 fit into 3? No. Place a 0.

  7. 7

    Does 4 fit into 3? No. Place a 0.

  8. 8

    Does 2 fit into 3? Yes. Place a 1. Remainder: 3 - 2 = 1.

  9. 9

    Does 1 fit into 1? Yes. Place a 1. Remainder: 1 - 1 = 0.

  10. 10

    The 8-bit binary number is 10010011.

Worked example 22 marks

Convert the binary number 11010110 into a denary number.

  1. 1

    Write the binary number under the place values: 128, 64, 32, 16, 8, 4, 2, 1.

  2. 2

    Binary: 1 1 0 1 0 1 1 0

  3. 3

    Add the place values where there is a '1': 128 + 64 + 16 + 4 + 2.

  4. 4

    Calculation: 128 + 64 = 192. 192 + 16 = 208. 208 + 4 = 212. 212 + 2 = 214.

  5. 5

    The denary number is 214.

Recap

  • To convert from denary to binary, use subtraction of place values starting from the largest.
  • To convert from binary to denary, add the place values of all positions containing a '1'.
  • Binary place values are powers of 2 (1, 2, 4, 8, 16, 32, 64, 128...).
  • Always check that your answer is in the correct format, such as an 8-bit number if specified.

Quick check

  1. Convert the denary number 17 to a 5-bit binary number.1 mark
  2. What is the denary value of the binary number 10101?1 mark

3. Conversions Involving Hexadecimal

Hexadecimal is useful because it provides a simple way to represent large binary numbers. The conversion is straightforward because one hexadecimal digit maps directly to a four-bit binary sequence, known as a nibble. To convert from binary to hex, split the binary number into groups of 4 bits from right to left, then convert each group to its corresponding hex digit. To convert from hex to binary, simply reverse the process, converting each hex digit into its 4-bit binary equivalent. To convert between denary and hex, it's often easiest to use binary as an intermediate step.

Key term

Nibble: A four-bit group, which can be represented by a single hexadecimal digit.

Fun fact

In web development, colours are often defined using hexadecimal codes like #FFC0CB (pink). Each pair of hex digits represents the amount of Red, Green, and Blue light, from 00 (0) to FF (255).

Worked example 13 marks

Convert the binary number 111001011001 to hexadecimal.

  1. 1

    Split the binary number into 4-bit nibbles from the right: 1110 0101 1001.

  2. 2

    Convert each nibble to its denary/hex value.

  3. 3

    1110 = (8+4+2) = 14, which is 'E' in hexadecimal.

  4. 4

    0101 = (4+1) = 5, which is '5' in hexadecimal.

  5. 5

    1001 = (8+1) = 9, which is '9' in hexadecimal.

  6. 6

    Combine the digits: E59. The hexadecimal number is E59.

Worked example 24 marks

Convert the hexadecimal number 3A9 to denary.

  1. 1

    First, convert the hexadecimal number to binary. Convert each digit to its 4-bit binary equivalent.

  2. 2

    3 = 0011

  3. 3

    A (10) = 1010

  4. 4

    9 = 1001

  5. 5

    Combine the binary nibbles: 001110101001.

  6. 6

    Now, convert this binary number to denary by adding the place values.

  7. 7

    Place values: ..., 2048, 1024, 512, 256, 128, 64, 32, 16, 8, 4, 2, 1

  8. 8

    001110101001 = 512 + 256 + 128 + 32 + 8 + 1.

  9. 9

    Calculation: 512+256=768, 768+128=896, 896+32=928, 928+8=936, 936+1=937.

  10. 10

    The denary number is 937.

Recap

  • One hexadecimal digit represents exactly four binary bits (a nibble).
  • To convert binary to hex, group into 4s from the right.
  • To convert hex to binary, change each hex digit to its 4-bit binary pattern.
  • Converting between denary and hex is easiest by using binary as an intermediate step.
  • Memorise the hex values for 10-15: A=10, B=11, C=12, D=13, E=14, F=15.

Quick check

  1. Convert the hexadecimal number F2 into a binary number.2 marks
  2. Convert the binary number 10110001 into a hexadecimal number.2 marks

4. Binary Addition and Overflow

Adding binary numbers follows simple rules, similar to denary addition. The results of adding two bits are straightforward, but you must handle the 'carry' when the sum is 2 or more. An overflow error occurs when the result of an addition is too large to fit into the number of bits available (e.g., trying to store 256 in an 8-bit register, which can only hold values up to 255). In an 8-bit system, this is detected when there is a carry bit out of the most significant bit (the leftmost bit).

0 + 0 = 0

0 + 1 = 1

1 + 0 = 1

1 + 1 = 0, carry 1

1 + 1 + 1 = 1, carry 1

Key term

Overflow Error: An error that occurs when the result of a calculation is too large to be stored in the available number of bits.

Examiner insight

Examiners require you to show your working, including all carry bits. Simply writing the final answer, even if correct, may not earn full marks.

Common pitfall

The most frequent error is mishandling the carry bit, especially in a column that already has a carry, resulting in 1 + 1 + 1. Remember this equals 1 with a carry of 1.

Worked example 13 marks

Add the two 8-bit binary numbers: 01101011 and 00110100.

  1. 1

    Set up the addition column by column, from right to left. Show carries above the next column.

  2. 2

    ¹ ¹ ¹ ¹

  3. 3

    01101011

  4. 4

    + 00110100

  5. 5

    ----------

  6. 6

    10011111

  7. 7

    Rightmost column (1): 1 + 0 = 1.

  8. 8

    Column 2: 1 + 0 = 1.

  9. 9

    Column 3: 0 + 1 = 1.

  10. 10

    Column 4: 1 + 0 = 1.

  11. 11

    Column 5: 0 + 1 = 1.

  12. 12

    Column 6: 1 + 1 = 0, carry 1.

  13. 13

    Column 7: 1 + 1 + (carry 1) = 1, carry 1.

  14. 14

    Column 8 (MSB): 0 + 0 + (carry 1) = 1.

  15. 15

    The result is 10011111.

Worked example 23 marks

Add the two 8-bit binary numbers 11001000 and 01001000. Has an overflow error occurred?

  1. 1

    Set up the addition:

  2. 2

    ¹

  3. 3

    11001000

  4. 4

    + 01001000

  5. 5

    ----------

  6. 6

    (1)00010000

  7. 7

    Working from right to left, the first few columns are simple additions of 0+0.

  8. 8

    Column 4: 1+1 = 0, carry 1.

  9. 9

    Column 5: 0+0+carry 1 = 1.

  10. 10

    Column 6: 0+0 = 0.

  11. 11

    Column 7: 1+1 = 0, carry 1.

  12. 12

    Column 8 (MSB): 1+0+carry 1 = 0, carry 1.

  13. 13

    The 8-bit result is 00010000.

  14. 14

    Yes, an overflow error has occurred because there was a carry out of the most significant bit (the 8th bit).

Recap

  • Binary addition follows four main rules, including 1+1 = 0 carry 1.
  • Always work from right to left, column by column.
  • Clearly write down any carry bits into the next column.
  • An overflow error happens when the sum is too large for the number of bits.
  • In unsigned binary addition, overflow is indicated by a carry out of the most significant bit.

Quick check

  1. Add the binary numbers 1011 and 0101.2 marks
  2. In an 8-bit system, what is the largest denary number you can represent before an overflow occurs?1 mark

5. Logical Binary Shifts

A binary shift moves every bit in a binary number to the left or right. In a logical shift, the empty spaces created by the shift are filled with zeros. A logical left shift has the effect of multiplying the number by 2 for every place shifted. A logical right shift has the effect of dividing the number by 2 (integer division) for every place shifted. Bits that are shifted out of the register are discarded.

Left shift by n places: Number × 2^n

Right shift by n places: Number ÷ 2^n (integer division)

Key term

Logical Shift: A bitwise operation that shifts all bits of a binary number left or right and fills the vacant bit positions with zeros.

Common pitfall

Forgetting that a right shift performs integer division, meaning any remainder is lost. For example, a right shift on 00000111 (denary 7) results in 00000011 (denary 3), not 3.5.

Worked example 12 marks

Perform a logical left shift of 2 places on the 8-bit binary number 00011010.

  1. 1

    The original number is 00011010.

  2. 2

    A left shift of 1 place moves all bits one position to the left. A zero is added to the right. The leftmost bit is discarded. Result: 00110100.

  3. 3

    A left shift of 2 places repeats the process. Result: 01101000.

  4. 4

    The two leftmost bits (00) were discarded, and two zeros were added on the right.

  5. 5

    Final Answer: 01101000.

Worked example 23 marks

What is the denary effect of performing a logical right shift of 3 places on the binary number 11100000?

  1. 1

    First, find the denary value of the original number: 11100000.

  2. 2

    128 + 64 + 32 = 224.

  3. 3

    Perform a logical right shift of 3 places: 11100000 becomes 00011100.

  4. 4

    The three rightmost bits (000) were discarded, and three zeros were added on the left.

  5. 5

    Now, find the denary value of the new number: 00011100.

  6. 6

    16 + 8 + 4 = 28.

  7. 7

    The mathematical effect is division by 2^3 (or 8).

  8. 8

    Check: 224 / 8 = 28. The effect is integer division by 8.

Recap

  • A logical left shift multiplies a binary number by a power of 2.
  • A logical right shift performs integer division by a power of 2.
  • In a logical shift, any new bits added are always zeros.
  • Bits shifted beyond the end of the register are lost.

Quick check

  1. What is the result of a 1-place logical left shift on 01010101?1 mark
  2. What is the mathematical effect of a 4-place logical left shift?1 mark

6. Two's Complement for Negative Numbers

Computers need a way to represent negative numbers in binary. Two's complement is the most common method. In this system, a fixed number of bits is used, and the most significant bit (MSB) indicates the sign: 0 for positive, 1 for negative. To find the two's complement representation of a negative number (e.g., -45), you first write out the binary for the positive version (+45), then invert all the bits (0s become 1s, 1s become 0s), and finally add 1 to the result.

Negative Value = Invert Bits(Positive Value) + 1

Key term

Two's Complement: A method for representing signed integers where negative numbers are calculated by inverting all bits of the positive number and adding one.

Examiner insight

When converting a negative two's complement number to denary, examiners reward the alternative method (using a negative place value for the MSB) as it's often quicker and less prone to error than the reverse 'subtract 1 and invert' process.

Common pitfall

Forgetting to perform one of the two steps: either inverting the bits or adding 1. Both are required to correctly form the two's complement.

Worked example 13 marks

Represent the denary number -35 in 8-bit two's complement.

  1. 1

    Step 1: Find the 8-bit binary for the positive number, +35.

  2. 2

    35 = 32 + 2 + 1. So, +35 is 00100011.

  3. 3

    Step 2: Invert all the bits (One's Complement).

  4. 4

    00100011 becomes 11011100.

  5. 5

    Step 3: Add 1 to the result.

  6. 6

    11011100 + 1 = 11011101.

  7. 7

    So, -35 in 8-bit two's complement is 11011101.

Worked example 23 marks

What is the denary value of the 8-bit two's complement number 11110100?

  1. 1

    The MSB is 1, so the number is negative.

  2. 2

    To find its positive magnitude, we reverse the process: subtract 1, then invert the bits.

  3. 3

    Step 1: Subtract 1. 11110100 - 1 = 11110011.

  4. 4

    Step 2: Invert the bits. 11110011 becomes 00001100.

  5. 5

    Step 3: Convert this binary number to denary.

  6. 6

    00001100 = 8 + 4 = 12.

  7. 7

    Therefore, the original number represented -12.

  8. 8

    Alternative Method: The MSB has a negative place value (-128). Add this to the other place values: -128 + 64 + 32 + 16 + 4 = -12.

Recap

  • Two's complement is used to represent negative integers in binary.
  • The most significant bit (MSB) acts as a sign bit: 0 for positive, 1 for negative.
  • To make a number negative, write its positive binary form, invert the bits, and add 1.
  • To convert a negative two's complement number to denary, reverse the process: subtract 1, invert, then convert to denary.

Quick check

  1. What is the 8-bit two's complement representation of -1?2 marks
  2. In an 8-bit two's complement system, what does the MSB of 1 indicate?1 mark

End-of-chapter exercise

Test yourself on the whole chapter. Work through these before moving on.

  1. Describe the key difference between the denary and binary number systems, mentioning the base of each.2 marks
  2. Convert the denary number 45 to an 8-bit binary number.2 marks
  3. Convert the hexadecimal number 4B to a 12-bit binary number and then convert this binary number to denary. Show your working.4 marks
  4. Add the following two 8-bit binary numbers: 01011100 and 00110110. Show your carry bits.3 marks
  5. Add the following two 8-bit binary numbers: 11010111 and 01101101. State whether an overflow error has occurred and justify your answer.4 marks
  6. A computer stores the 8-bit binary number 00110100. What is the result after a logical left shift of 2 places? Give your answer in both binary and denary.3 marks
  7. Convert the denary number 219 to hexadecimal. Show your method.3 marks
  8. Using 8-bit two's complement, find the binary representation of the denary number -42. Show all your working.3 marks
  9. What denary number is represented by the 8-bit two's complement binary number 10101110? Show your working.3 marks
  10. Explain why a programmer might prefer to use hexadecimal rather than binary when viewing data in a memory dump.2 marks

Go deeper

Practise and revise with member-only material for this chapter.

Free notes are just the start.

Unlock every Workbook and Chapter at a Glance, and generate your own worksheets and predicted papers.

Explore plans

Related chapters