Cambridge IGCSE0478

Number systems

Computer Science 0478 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.

~15 min read

1. Denary and Binary Number Systems

In everyday life, we use the denary (or base-10) number system, which uses ten digits (0-9). Each column in a denary number represents a power of 10 (1, 10, 100, 1000, etc.). For example, the number 345 is (3 x 100) + (4 x 10) + (5 x 1). Computers, however, are built from electronic circuits that can only be in one of two states: on or off. These states are represented by the digits 1 (on) and 0 (off). This is called the binary (or base-2) number system. In binary, each column represents a power of 2 (1, 2, 4, 8, 16, etc.). All data, including numbers, text, and images, must be converted into binary to be processed by a computer.

Denary Place Values: ... 10^3 (1000), 10^2 (100), 10^1 (10), 10^0 (1)

Binary Place Values: ... 2^7 (128), 2^6 (64), 2^5 (32), 2^4 (16), 2^3 (8), 2^2 (4), 2^1 (2), 2^0 (1)

Key term

Bit: The smallest unit of data in a computer, represented as either a 0 or a 1, corresponding to an on or off electrical state.

Examiner insight

Examiners award marks for clearly explaining *why* computers use binary, linking it to the two-state (on/off) nature of electronic circuits.

Common pitfall

Simply stating that computers use 0s and 1s without explaining that this represents the on/off state of transistors or logic gates.

Fun fact

A group of 8 bits is called a 'byte'. Half a byte, or 4 bits, is humorously called a 'nibble'.

Worked example 14 marks

Describe the difference between a denary number system and a binary number system. [4]

  1. 1

    The denary system is base-10, meaning it uses ten distinct digits (0, 1, 2, 3, 4, 5, 6, 7, 8, 9).

  2. 2

    The binary system is base-2, meaning it uses only two distinct digits (0 and 1).

  3. 3

    In denary, the place value of each column increases by a power of 10 (e.g., 1, 10, 100).

  4. 4

    In binary, the place value of each column increases by a power of 2 (e.g., 1, 2, 4, 8). Humans use denary, while computers use binary to represent the on/off state of circuits.

Recap

  • Denary is a base-10 system used by humans, with digits 0-9.
  • Binary is a base-2 system used by computers, with digits 0 and 1.
  • Computers use binary because their circuits exist in two states: on (1) and off (0).
  • The place values in denary are powers of 10, while in binary they are powers of 2.

Quick check

  1. How many digits are used in the binary number system?1 mark
  2. Why is the binary system suitable for use in computers?1 mark

2. Converting Between Denary and Binary

To allow computers to process our numbers, we must convert from denary to binary, and to understand a computer's output, we must convert from binary to denary. An 8-bit binary number is called a byte.

Denary to Binary Conversion: Use the place value subtraction method. Write out the binary place values (128, 64, 32, 16, 8, 4, 2, 1). Starting from the largest place value (128), check if it is less than or equal to your denary number. If it is, place a '1' under it and subtract its value from your number. If not, place a '0'. Repeat this process for each subsequent place value with the new remainder.

Binary to Denary Conversion: This is simpler. Write the binary place values above your binary number. Add up all the place values that have a '1' underneath them. The total is the denary equivalent.

Key term

Byte: A group of 8 bits, which is the standard unit of storage used to represent a single character, such as a letter or a symbol.

Examiner insight

For denary-to-binary conversions, marks are awarded for showing the subtraction working or the place value method clearly. A correct answer with no working may not receive full marks.

Common pitfall

Forgetting to include placeholder zeros for place values that are not used in a denary-to-binary conversion, leading to an incorrect number of bits (e.g., writing 1101 for 13 instead of 00001101 in 8-bit).

Worked example 12 marks

Convert the denary number 150 to an 8-bit binary number. [2]

  1. 1

    Place values: 128, 64, 32, 16, 8, 4, 2, 1.

  2. 2

    150 >= 128? Yes. Place '1'. Remainder: 150 - 128 = 22.

  3. 3

    22 >= 64? No. Place '0'.

  4. 4

    22 >= 32? No. Place '0'.

  5. 5

    22 >= 16? Yes. Place '1'. Remainder: 22 - 16 = 6.

  6. 6

    6 >= 8? No. Place '0'.

  7. 7

    6 >= 4? Yes. Place '1'. Remainder: 6 - 4 = 2.

  8. 8

    2 >= 2? Yes. Place '1'. Remainder: 2 - 2 = 0.

  9. 9

    0 >= 1? No. Place '0'.

  10. 10

    Result: 10010110

Worked example 21 mark

Convert the 8-bit binary number 01101101 to a denary number. [1]

  1. 1

    Write place values above the binary number: (64) (32) (8) (4) (1)

  2. 2

    The bits set to '1' are at positions 64, 32, 8, 4, and 1.

  3. 3

    Add the corresponding place values: 64 + 32 + 8 + 4 + 1.

  4. 4

    Result: 109

Recap

  • To convert denary to binary, use the subtraction method starting from the largest place value.
  • To convert binary to denary, add up the place values for every '1' in the number.
  • An 8-bit binary number is known as a byte.
  • Always use all 8 bits for a byte, including leading zeros if necessary.
  • The largest denary number an 8-bit binary number can represent is 255 (11111111).

Quick check

  1. What is the largest denary number that can be represented using 4 bits?1 mark
  2. Convert the denary number 65 to an 8-bit binary number.1 mark

3. The Hexadecimal Number System

Binary numbers can be very long and difficult for humans to read and write without making errors. The hexadecimal (or base-16) system is used as a more compact, human-friendly way to represent binary data. It uses 16 symbols: the digits 0-9 and the letters A-F to represent the denary values 10-15. The key relationship is that one hexadecimal digit represents exactly four binary bits (a nibble). Hexadecimal is commonly used in computing for representing MAC addresses, memory locations (memory dumps), and HTML/CSS colour codes.

Hex 'A' = Denary 10

Hex 'B' = Denary 11

Hex 'C' = Denary 12

Hex 'D' = Denary 13

Hex 'E' = Denary 14

Hex 'F' = Denary 15

Key term

Hexadecimal: A base-16 number system using digits 0-9 and letters A-F, often used as a shorthand representation for binary data.

Examiner insight

Students who can give and briefly explain practical examples of where hexadecimal is used (e.g., MAC addresses, memory dumps, colour codes) often score higher marks.

Fun fact

The error message you might see when a program crashes, known as a 'memory dump', is shown in hexadecimal because it's a compact way to display the raw binary data from the computer's memory.

Worked example 12 marks

State two common uses of hexadecimal numbers in computer science. [2]

  1. 1

    Use 1: Representing MAC (Media Access Control) addresses, which uniquely identify network devices.

  2. 2

    Use 2: Defining colours in HTML and CSS, where values for Red, Green, and Blue are specified (e.g., #FF0000 for pure red).

Recap

  • Hexadecimal is a base-16 number system.
  • It uses the symbols 0-9 and A-F.
  • Hexadecimal is used as a human-friendly shorthand for long binary strings.
  • One hexadecimal digit represents a group of four binary bits (a nibble).
  • Common uses include MAC addresses, memory dumps, and web colour codes.

Quick check

  1. What denary value does the hexadecimal digit 'E' represent?1 mark
  2. Why do programmers often use hexadecimal instead of binary?1 mark

4. Converting Between Binary and Hexadecimal

The simple relationship between binary and hexadecimal (1 hex digit = 4 binary bits) makes conversion straightforward.

Binary to Hexadecimal:

  1. Split the binary number into groups of 4 bits (nibbles), starting from the right.
  2. If the leftmost group has fewer than 4 bits, add leading zeros to make it a group of 4.
  3. Convert each 4-bit nibble into its corresponding hexadecimal digit.

Hexadecimal to Binary:

  1. Take each hexadecimal digit individually.
  2. Convert each digit into its 4-bit binary equivalent. Remember to include leading zeros to ensure each group has 4 bits (e.g., hex 7 is 0111, not 111).
  3. Combine the 4-bit groups to form the final binary string.

Key term

Nibble: A group of four bits, which can be conveniently represented by a single hexadecimal digit.

Examiner insight

Examiners look for the clear grouping of binary digits into nibbles (4-bit chunks) when converting to hexadecimal. Drawing lines or leaving spaces between the nibbles is good practice.

Common pitfall

When converting from binary to hex, grouping the bits from left-to-right instead of right-to-left. This causes an error if the total number of bits is not a multiple of 4.

Worked example 12 marks

Convert the 12-bit binary number 101000011100 into hexadecimal. [2]

  1. 1

    Split the binary number into 4-bit nibbles: 1010 0001 1100.

  2. 2

    Convert the first nibble: 1010 = (8 + 2) = 10, which is 'A' in hexadecimal.

  3. 3

    Convert the second nibble: 0001 = 1, which is '1' in hexadecimal.

  4. 4

    Convert the third nibble: 1100 = (8 + 4) = 12, which is 'C' in hexadecimal.

  5. 5

    Combine the digits: A1C

Worked example 22 marks

Convert the hexadecimal number 4D into an 8-bit binary number. [2]

  1. 1

    Take the first digit, '4'. Its 4-bit binary equivalent is 0100.

  2. 2

    Take the second digit, 'D'. 'D' is 13 in denary. Its 4-bit binary equivalent is 1101 (8 + 4 + 1).

  3. 3

    Combine the two 4-bit groups: 01001101.

  4. 4

    The 8-bit binary number is 01001101.

Recap

  • To convert binary to hex, group bits into nibbles (4s) from right to left.
  • Convert each nibble into a single hexadecimal digit.
  • To convert hex to binary, convert each hex digit into a 4-bit binary string.
  • Always ensure each binary group has exactly 4 bits, adding leading zeros if needed.

Quick check

  1. Convert the binary number 11110011 to hexadecimal.1 mark
  2. Convert the hexadecimal number B2 to 8-bit binary.1 mark

5. Binary Addition and Overflow

Adding binary numbers follows a few simple rules. When you add two bits, you might also have a 'carry' bit from the previous column.

The Rules of Binary Addition:

  • 0 + 0 = 0
  • 0 + 1 = 1
  • 1 + 0 = 1
  • 1 + 1 = 0, carry 1 to the next column
  • 1 + 1 + 1 = 1, carry 1 to the next column (this happens when you have a carry from the previous column)

An overflow error occurs when the result of an addition is too large to fit into the number of bits available (e.g., the register size). In an 8-bit addition, this happens if there is a carry bit out of the most significant (leftmost) column. This lost bit means the stored result is incorrect.

0 + 0 = 0

0 + 1 = 1

1 + 1 = 10 (0 with a carry of 1)

1 + 1 + 1 = 11 (1 with a carry of 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, leading to a loss of data.

Examiner insight

In binary addition questions, full marks are only given if all the 'carry' bits are clearly shown in the working. Simply writing the final answer is not enough.

Common pitfall

Forgetting to add the 'carry' bit in the next column during binary addition, especially in the 1+1+1 case.

Worked example 13 marks

Add the two 8-bit binary values: 00110111 and 01110011. Show your working. [3]

  1. 1

    Set up the addition, aligning the columns. Write carry bits above.

  2. 2

    11 111 (Carry bits)

  3. 3

    00110111

  4. 4

    + 01110011

  5. 5

    ----------

  6. 6

    10101010

  7. 7

    Working from right to left:

  8. 8

    Col 1 (LSB): 1+1 = 0 carry 1

  9. 9

    Col 2: 1+1+1(carry) = 1 carry 1

  10. 10

    Col 3: 1+0+1(carry) = 0 carry 1

  11. 11

    Col 4: 0+0+1(carry) = 1

  12. 12

    Col 5: 1+1 = 0 carry 1

  13. 13

    Col 6: 1+1+1(carry) = 1 carry 1

  14. 14

    Col 7: 0+0+1(carry) = 1

  15. 15

    Col 8 (MSB): 0+0 = 0. Final answer is 10101010.

Worked example 23 marks

Add the two 8-bit binary numbers 11001000 and 01010010. State whether an overflow error has occurred. [3]

  1. 1

    Set up the addition:

  2. 2

    1 1 (Carry bits)

  3. 3

    11001000

  4. 4

    + 01010010

  5. 5

    ----------

  6. 6

    1 00011010

  7. 7

    The calculation is: 11001000 + 01010010 = 100011010.

  8. 8

    The result has 9 bits, but we only have an 8-bit register. There is a carry bit from the most significant column.

  9. 9

    An overflow error has occurred because the result cannot be stored in 8 bits.

Recap

  • Binary addition is performed column by column from right to left.
  • The rule 1 + 1 = 0 carry 1 is the most important to remember.
  • An overflow error happens when a calculation produces a result that is too large for the register.
  • You can spot an overflow in unsigned addition if there is a carry out of the most significant bit.
  • Always show your carry bits in your working.

Quick check

  1. What is the result of 1 + 1 + 1 in binary?1 mark
  2. What is an overflow error?1 mark

6. Manipulating Numbers with Binary Shifts

A binary shift is an operation that moves the bits in a binary number to the left or right. This is a very fast and efficient way for a processor to perform multiplication and division by powers of 2.

Logical Left Shift: All bits are shifted a number of places to the left. Zeros are added to the empty positions on the right. Bits shifted off the left end are discarded. A logical left shift of 'n' places is equivalent to multiplying the number by 2^n.

Logical Right Shift: All bits are shifted a number of places to the right. Zeros are added to the empty positions on the left. Bits shifted off the right end are discarded. A logical right shift of 'n' places is equivalent to performing an integer division by 2^n (i.e., division where any remainder is ignored).

Left Shift by n places = Multiplication by 2^n

Right Shift by n places = Integer Division by 2^n

Key term

Logical Shift: A bitwise operation that shifts all bits in a register to the left or right, filling the empty spaces with zeros and discarding bits shifted out.

Examiner insight

Marks are awarded for correctly stating the arithmetic effect of a shift (e.g., 'a left shift of 2 places multiplies the number by 4'). Simply performing the shift is only part of the answer.

Common pitfall

Confusing the effect of a left shift with division and a right shift with multiplication. Remember: Left = Larger (multiply), Right = Reduced (divide).

Worked example 14 marks

Perform a logical left shift of 2 places on the 8-bit binary number 00011010. State the denary equivalent before and after the shift. [4]

  1. 1

    Original number: 00011010.

  2. 2

    Denary equivalent before: 16 + 8 + 2 = 26.

  3. 3

    Shift left by 2 places: The two leftmost bits (00) are discarded. Two zeros are added on the right.

  4. 4

    Resulting number: 01101000.

  5. 5

    Denary equivalent after: 64 + 32 + 8 = 104.

  6. 6

    Check: The shift has the effect of multiplying by 2^2 = 4. 26 * 4 = 104. The result is correct.

Worked example 22 marks

Perform a logical right shift of 3 places on the 8-bit binary number 10110100. State the arithmetic effect of this shift. [2]

  1. 1

    Original number: 10110100.

  2. 2

    Shift right by 3 places: The three rightmost bits (100) are discarded. Three zeros are added on the left.

  3. 3

    Resulting number: 00010110.

  4. 4

    The arithmetic effect of a logical right shift of 3 places is integer division by 2^3, which is division by 8.

Recap

  • A logical left shift multiplies a binary number by a power of 2.
  • A logical right shift performs integer division on a binary number by a power of 2.
  • In a left shift, zeros are added to the right (Least Significant Bit side).
  • In a logical right shift, zeros are added to the left (Most Significant Bit side).
  • Bits that are shifted beyond the end of the register are lost.

Quick check

  1. What is the arithmetic effect of a logical left shift of 1 place?1 mark
  2. What happens to the bit that is shifted off the end in a right shift?1 mark

7. Representing Negative Numbers: Two's Complement

Standard binary can only represent positive numbers. To represent negative numbers, computers use a system called Two's Complement. In this system, the most significant bit (MSB) of a number has a negative place value. For an 8-bit number, the place values are -128, 64, 32, 16, 8, 4, 2, 1. A '1' in the MSB position indicates a negative number.

To find the two's complement representation of a negative number (e.g., -75):

  1. Find the binary representation of the positive number (e.g., +75 = 01001011).
  2. Invert all the bits (1s become 0s, 0s become 1s). This gives 10110100.
  3. Add 1 to the result. 10110100 + 1 = 10110101. So, -75 is 10110101 in two's complement.

Key term

Two's Complement: A method for representing signed integers (positive and negative) in binary, where the most significant bit has a negative weight.

Examiner insight

Examiners look for a clear two-step process: inverting the bits and then adding one. Simply stating the final answer without showing these steps will lose marks.

Common pitfall

Forgetting the second step of the two's complement process (adding 1 after inverting the bits). This is a very common error.

Worked example 13 marks

Using 8 bits, find the two's complement representation of the denary number -45. [3]

  1. 1

    Step 1: Find the 8-bit binary for +45. 45 = 32 + 8 + 4 + 1. This is 00101101.

  2. 2

    Step 2: Invert all the bits. 00101101 becomes 11010010.

  3. 3

    Step 3: Add 1 to the inverted result. 11010010 + 1 = 11010011.

  4. 4

    The two's complement representation of -45 is 11010011.

Worked example 22 marks

An 8-bit register stores a number in two's complement form: 10110111. What is its denary value? [2]

  1. 1

    The number starts with a 1, so it is negative. The MSB has a value of -128.

  2. 2

    Write the place values: -128, 64, 32, 16, 8, 4, 2, 1.

  3. 3

    Add the values for each '1' bit: (-128) + 32 + 16 + 4 + 2 + 1.

  4. 4

    Calculation: -128 + 55 = -73.

  5. 5

    The denary value is -73.

Recap

  • Two's complement is used to represent both positive and negative integers.
  • The Most Significant Bit (MSB) has a negative place value (e.g., -128 for 8 bits).
  • If the MSB is 0, the number is positive. If it is 1, the number is negative.
  • To make a number negative, invert all its bits and then add 1.
  • An 8-bit two's complement number can represent values from -128 to +127.

Quick check

  1. In an 8-bit two's complement number, what is the place value of the most significant bit?1 mark
  2. What is the two-step process to find the two's complement of a positive number?2 marks

End-of-chapter exercise

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

  1. Convert the denary number 195 into an 8-bit binary number.2 marks
  2. Convert the 8-bit binary number 11010110 into a denary number.1 mark
  3. A device has the MAC address 4A-B3-19. Convert the first two parts (4A-B3) into a 16-bit binary number.4 marks
  4. Add the two 8-bit binary numbers 01011101 and 00110110. Show all your carry bits.3 marks
  5. The 8-bit binary number 00101100 is shifted two places to the left. State the resulting binary number and its final denary value.3 marks
  6. Using an 8-bit register, show how the computer would represent the denary number -100 using two's complement. Show your working.3 marks
  7. A computer adds the two 8-bit binary numbers 10110101 and 10011100. Calculate the 9-bit result and explain why an overflow error occurs.4 marks
  8. Convert the 12-bit binary number 111010010101 into hexadecimal.2 marks
  9. An 8-bit register holds the two's complement number 10001110. Convert this to its denary equivalent.2 marks
  10. Explain why hexadecimal is often used to represent binary data, giving one specific example of its use.3 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