GCSE Computer Science · Topic guide

Trace Tables and Binary/Hex Conversions

Trace tables and binary/hexadecimal conversions are two of the most heavily examined technique-based skills in GCSE Computer Science. A trace table dry runs an algorithm by hand, recording how every variable's value changes line by line and loop by loop, without a computer to run the code. Conversions require moving confidently between denary, binary and hexadecimal without a calculator, including binary place values, division-remainder hex conversion and splitting binary into 4-bit nibbles. Both skills are assessed throughout Paper 2, and are often combined in the same question, for example a trace table for a loop followed by a request to convert the final output into another number system.

GCSE Grades 1-9Paper 2: Computational Thinking, Algorithms and ProgrammingOCR J277AQAEdexcelWJECEduqas

Before you start

Make sure you're comfortable with these topics first:

Method

  1. Before tracing, list every variable named in the algorithm as a column heading, plus a column for any OUTPUT, in the exact order each one first appears.
  2. Work through the pseudocode one line at a time, from first to last, only updating a variable's column when that specific line changes it, and copying down any value that has not changed.
  3. For a loop, add one new row every time the loop body runs, and track the loop counter itself as its own column so it is clear exactly when the loop stops.
  4. Never skip ahead to the final answer: write out every intermediate row, since exam mark schemes usually give credit for correct intermediate values as well as the final answer.
  5. For binary-to-denary, write the place values above each bit (128, 64, 32, 16, 8, 4, 2, 1 for 8 bits) and add together only the place values where the bit is a 1.
  6. For denary-to-binary, starting from the largest place value, ask 'does this fit': if yes, write 1 and subtract it from the remaining total; if no, write 0 and move to the next place value.
  7. For denary-to-hexadecimal, divide repeatedly by 16, writing down each remainder (converting any remainder of 10-15 to A-F), then read the remainders in reverse order, last remainder first.
  8. For binary-to-hexadecimal, split the binary number into groups of 4 bits (nibbles) starting from the right, and convert each nibble to a single hex digit using its own place values, 8, 4, 2, 1.

Worked example

A pseudocode algorithm is: total <- 0, FOR i <- 1 TO 3, total <- total + (i x 5), NEXT i, OUTPUT total. (a) Complete a trace table showing the value of i and total after each pass of the loop. (b) Convert the final value of total into an 8-bit binary number, then into hexadecimal.

  1. Set up trace table columns for i and total, noting total starts at 0 before the loop begins, then trace pass 1: i = 1, total = 0 + (1 x 5) = 5.
  2. Trace pass 2: i = 2, total = 5 + (2 x 5) = 5 + 10 = 15.
  3. Trace pass 3: i = 3, total = 15 + (3 x 5) = 15 + 15 = 30; the loop then ends because i has reached the FOR loop's upper limit of 3, so the algorithm outputs total = 30.
  4. Convert 30 to 8-bit binary using the place values 128, 64, 32, 16, 8, 4, 2, 1: 30 is less than 128, 64 and 32 (all 0); 30 >= 16 (write 1, remainder 14); 14 >= 8 (write 1, remainder 6); 6 >= 4 (write 1, remainder 2); 2 >= 2 (write 1, remainder 0); giving 00011110.
  5. Split 00011110 into two nibbles, 0001 and 1110, and convert each to a hex digit: 0001 = 1, 1110 = 8+4+2 = 14 = E.
  6. Final answer: the trace table gives an output of 30; written as 8-bit binary this is 00011110, and as hexadecimal this is 1E.

Practice questions

Type your answer and press Check to be marked straight away, or reveal the answer and mark yourself.

Q1Convert the denary number 39 to an 8-bit binary number, showing your working.Show answer

Answer: 00100111 (32 + 4 + 2 + 1 = 39)

Got it right?
Q2Convert the 8-bit binary number 01011010 to denary.Show answer

Answer: 90 (64 + 16 + 8 + 2)

Got it right?
Q3Convert the denary number 200 to hexadecimal, showing your working.Show answer

Answer: C8 (200 = 12 x 16 + 8, and 12 = C)

Got it right?
Q4Convert the hexadecimal number 3F to denary.Show answer

Answer: 63 (3 x 16 + 15)

Got it right?
Q5Convert the 8-bit binary number 10110100 directly to hexadecimal by splitting it into nibbles.Show answer

Answer: B4 (1011 = 8+2+1 = 11 = B, 0100 = 4)

Got it right?
Q6Convert the hexadecimal number FF to an 8-bit binary number.Show answer

Answer: 11111111 (F = 1111, so FF = 1111 1111)

Got it right?
Q7State how many different values can be represented using 5 bits, and explain your reasoning.Show answer

Answer: 32; each of the 5 bits can independently be 0 or 1, so the total number of combinations is 2^5 = 32

Got it right?
Q8A pseudocode algorithm is: count <- 0, x <- 10, WHILE x > 0, count <- count + 1, x <- x - 3, ENDWHILE, OUTPUT count. Complete a trace table for x and count, laid out as x | count, then state the value output.Show answer

Answer: x | count 10 | 0 7 | 1 4 | 2 1 | 3 -2 | 4 (loop ends here, -2 is not > 0) Output = 4

Got it right?

Exam-style questions

Written in the style of a GCSE Computer Science exam paper, with a full mark scheme.

Q1[4 marks]

A pseudocode algorithm is: total <- 1, FOR n <- 1 TO 4, total <- total x n, NEXT n, OUTPUT total. Complete a trace table showing the value of n and total after each pass of the loop, then state the value output.

Show mark scheme

Tick each line you got. Your score builds from the marks on the scheme.

Nothing ticked yet - 4 available

Got it right?
Q2[5 marks]

An 8-bit register stores the denary value 118. (a) Convert 118 to an 8-bit binary number, showing your working. (b) The 8-bit binary answer is then converted to hexadecimal. State the hexadecimal equivalent, showing your working.

Show mark scheme

Tick each line you got. Your score builds from the marks on the scheme.

Nothing ticked yet - 5 available

Got it right?
Q3[6 marks]

A programmer debugging a memory dump can choose to view each memory address as either an 8-bit binary number or its hexadecimal equivalent. Using the values 10110110 and B6 as an example, explain how hexadecimal represents the same information as binary, and evaluate why hexadecimal is generally preferred over binary when programmers read and write memory addresses or colour codes by hand.

Show mark scheme

Tick each line you got. Your score builds from the marks on the scheme.

Nothing ticked yet - 6 available

Got it right?

See real GCSE Computer Science past-paper questions, with official mark schemes

Free printable worksheet

Want more practice on paper? Download the trace tables and binary/hex conversions worksheet pack - 17 pages of exam-style questions with a full mark scheme. One email opens every download in this browser for 14 days - no account, no card. Print it for personal and classroom use.

Next topics

Ready to practise trace tables and binary/hex conversions? Add it to a printable topic pack for this student in the Pack Builder.

Add to my pack

Not quite what you needed?

Tell us what is missing on trace tables and binary/hex conversions, or which topic to write up next. Every request is read, and we reply to every one.

Build a full practice pack.

This topic is one of hundreds in the library - pick the ones a student needs and generate a printable PDF in minutes.