Data Representation

Data Representation

Hexadecimal uses, binary addition and overflow

Number Systems Paper 1 15 min read

On this page
  1. In this note
  2. What you should already know
  3. Why hexadecimal is used
  4. Where hexadecimal is used
  5. Adding two binary numbers
  6. Overflow
  7. Summary
  8. Ways they test it
  9. What the examiner looks for
  10. Past-paper questions, solved
  11. Common mistakes
  12. Practice
  13. Can I do this?
  14. Quiz

In this note

Syllabus 1.1 Number systems
  • 1.1.3Explain how and why hexadecimal is used as a beneficial way to represent data, and name where it is used.
  • 1.1.4Add two positive 8-bit binary integers, showing the carries.
  • 1.1.4Explain overflow and why it happens in binary addition.

Before this: Number systems (conversions). Next: Logical shifts and two's complement.

Part 1Learn the topic

The notes: every idea from the start, with our own examples.

What you should already know

Binary ↔ hex

One hex digit is exactly four bits: group binary in fours from the right.

Quick check: what is 1101 0010 in hex?

D2.

Adding in columns

In denary, 7 + 5 = 12: write 2 and carry 1 into the next column. Binary works the same way, but you carry as soon as a column reaches 2.

Quick check: in denary, what is carried in 8 + 6?

1 (8 + 6 = 14: write 4, carry 1).

Why hexadecimal is used

A computer never processes hexadecimal: inside, everything stays binary. Hex is used by people (programmers, technicians) as a short way of writing binary. Compare the same 16-bit value:

BinaryHexadecimal
1010 0000 0011 1101A03D

The hex is four characters instead of sixteen. That is the whole idea, and the benefits all come from it:

Shorter

A shorter representation of binary: one hex digit replaces four bits, so it takes up less space on screen or paper.

Easier for humans

Easier and quicker to read, write, understand and remember than a long string of 1s and 0s.

Fewer mistakes

Less likely to make a mistake copying or typing it, and easier to spot errors / debug.

Converts easily

Each hex digit is exactly 4 bits, so it converts straight to and from binary (no big sums, unlike denary).

Never say hex "uses less memory" or "is faster for the computer". The computer still stores the binary. Every benefit is for humans.

Where hexadecimal is used

UseWhat it looks likeWhat it is
HTML colour codes#FF8000a colour on a web page: two hex digits each for the amount of red, green and blue (00 to FF = 0 to 255)
MAC addresses00:1A:2B:3C:4D:5Ethe unique address of a network interface card (12 hex digits = 48 bits)
IPv6 addresses2001:0DB8:85A3::8A2E:0370:7334the address of a device on the internet (128 bits, written in groups of 4 hex digits)
Memory addresses and memory dumpsA2F, 0x7FF3A2locations in memory shown to a programmer when debugging
Error codes0x80070057codes shown when a program or device fails, so a technician can look them up
Assembly language / machine codeLDA &3Finstructions and values written in hex by low-level programmers
URLs%20 for a spacecharacters that can't appear in a web address are written as hex codes
Character codesASCII 41 = 'A'the ASCII / Unicode value of a character

Try it yourself

1
An HTML colour code is #00FF00. What is the denary value of the green part (the middle two digits)?
Show working
  1. FF = 15 × 16 + 15 = 255

Answer 255

2
How many bits does a MAC address of 12 hex digits use?
Show working
  1. 12 × 4 = 48

Answer 48

Adding two binary numbers

Binary addition works column by column from the right, exactly like denary, except that there are only two digits. There are only four sums to know:

Column adds up toWriteCarry to the next column
0 + 0 = 000
0 + 1 = 110
1 + 1 = 2 (binary 10)01
1 + 1 + 1 = 3 (binary 11), with a carry11

General methodAdding two 8-bit binary numbers

  1. Write the two numbers one under the other, lined up on the right. Leave a row above for the carries.
  2. Start at the rightmost column. Add the two bits and any carry.
  3. Write the result bit (0 or 1) underneath; write any carry above the next column to the left.
  4. Repeat for every column, moving left.
  5. If there is still a carry out of the leftmost (8th) column, it needs a 9th bit: that is overflow.
  6. Check: convert both numbers and the answer to denary; the sums must match.
0101 1011 + 0010 1110 = 1000 1001. Check: 91 + 46 = 137.
1286432168421
Carry111111
01011011
+00101110
Answer10001001
Show the carries. Mark schemes give a mark for "correct working, e.g. showing carries" on top of one mark per correct nibble. Write every carry above its column, even when you can do it in your head.

Try it yourself

1
Add 0011 0011 and 0111 1000.
Show working
  1. 51 + 120 = 171 = 1010 1011

Answer 1010 1011

2
Add 1001 1011 and 0001 0011.
Show working
  1. 155 + 19 = 174 = 1010 1110

Answer 1010 1110

Overflow

A register has a fixed number of bits. An 8-bit register can hold 0 to 255; a 16-bit register 0 to 65 535. Every computer and device has a predefined limit like this.

If the answer to a sum is too large to fit in the number of bits available, it would need an extra bit that the register does not have. This is an overflow error. The extra bit is lost and the value left in the register is wrong.

1100 1010 + 0111 0101: 202 + 117 = 319, more than 255. The 9th bit is the overflow; the register keeps only 0011 1111 = 63, which is wrong.
OF1286432168421
Carry11
11001010
+01110101
Answer100111111
Overflow in two marks: the result is greater than 255 (too large for the register) · it would need more than 8 bits / more bits than the register has.

Try it yourself

1
Add 1100 0011 and 0101 0000. Is there overflow?
Show working
  1. 195 + 80 = 275
  2. 275 needs 9 bits: 1 0001 0011

Answer 1 0001 0011: yes, overflow (195 + 80 = 275 > 255)

2
What is the largest number a 16-bit register can hold?
Show answer

Answer 65 535

Summary

  • Hex is for humans: a shorter representation of binary, easier to read, write, remember and debug, fewer mistakes, less screen space. It converts easily because one hex digit = 4 bits.
  • Uses of hex: HTML colour codes, MAC addresses, IPv6 addresses, memory addresses / dumps, error codes, assembly language, URLs, character codes.
  • Binary addition: 1 + 1 = 0 carry 1; 1 + 1 + 1 = 1 carry 1. Work right to left and show every carry.
  • Overflow: the result is too large for the number of bits in the register (over 255 for 8 bits), so an extra bit would be needed and the stored value is wrong.

If you see …

  • "Give a reason hexadecimal is used"a benefit FOR HUMANS: shorter / easier to read / fewer mistakes
  • "Show all your working" in an additionwrite the carry row
  • a carry out of the 8th columnshow the 9th bit and say overflow
Part 2How it is examined

Question types, what the examiner gives marks for, and real past-paper questions solved.

Ways they test it

Type 1 Benefit of hex

"Give one reason why the addresses are displayed in hexadecimal instead of binary" [1-2]

Spot it "instead of binary", "benefit", "reason a programmer may use hexadecimal".

  1. Pick one benefit per mark: shorter / easier to read / fewer mistakes / easier to debug / less screen space.
  2. Write it as a comparison: "it is shorter than binary".

Type 2 Uses of hex

"Identify two other ways hexadecimal is used in computer science" [2]

Spot it "identify", "other ways".

  1. Name two uses from the table, not the one already in the question.
  2. A name is enough for "identify".

Type 3 Binary addition

"Add the two 8-bit binary numbers using binary addition. Show all of your working" [3-4]

Spot it two 8-bit numbers one above the other.

  1. Carry row, then the answer.
  2. Marks: one per correct nibble, one for the carries, one more for showing the overflow bit when there is one.

Type 4 Explain overflow

"Explain why the overflow error occurred" [2]

Spot it "overflow".

  1. The result is greater than 255 / too large for the register.
  2. It needs more than 8 bits / the register has a fixed number of bits.

Type 5 Definition (multiple choice)

"Tick one box to show the correct definition of overflow" [1]

Spot it four statements.

  1. Choose "too large to represent in the number of bits available"; not "too small", not "negative".

What the examiner looks for

"Give two reasons why a programmer may use hexadecimal to represent binary" [2]

Marking points (one mark each, up to the marks shown)

  • Easier / quicker to understand, read or write
  • Easier / quicker to debug
  • Less likely to make a mistake
  • Shorter representation // takes up less screen space

Keywords shorter easier to read fewer errors debug

Too vague "takes less memory"; "the computer processes it faster"

"Explain why the overflow error occurred" [2]

Marking points (one mark each, up to the marks shown)

  • The result of the calculation is greater than 255 // the value is larger than can be stored in the register
  • The result would need more than 8 bits // a register has a predetermined number of bits and there are too many bits for it

Keywords greater than 255 more than 8 bits fixed number of bits

Too vague "the number is too big" with no mention of the bits or 255

A reason for using hexadecimal

0478/13/M/J/24 Q3Paper 1 · Computer systems1 mark
Give one reason why the addresses are displayed in hexadecimal instead of binary.
Credited
  • It is easier / quicker to read, understand or debug
  • It is a shorter representation of binary // takes up less screen space
Not credited
  • It uses less storage / memory
  • The computer can process it faster
Why

The computer stores binary whatever you display. Hex only helps the person reading it.

From: 0478/13/M/J/24 Q3(c) mark scheme

Past-paper questions, solved

0478/13/M/J/24 Q3Paper 1 · Computer systems8 marksFull size
Game debugging: memory addresses A2F and 000110011011, why hex, other uses

How to start Hex to binary is four bits per digit (keep the 0010). For binary to hex group in fours from the right. Parts (c) and (d) are recall.

Show a full-mark answer and the mark scheme

(a)(i) A = 1010, 2 = 0010, F = 1111 → 1010 0010 1111 (ii) 10 × 256 + 2 × 16 + 15 = 2607

(b)(i) 0001 | 1001 | 1011 → 19B (ii) 256 + 128 + 16 + 8 + 2 + 1 = 411

(c) It is shorter than binary, so it is easier to read and debug.

(d) HTML colour codes; MAC addresses.

PartAnswer / workingMarksGuidance
3(a)(i)1010 0010 1111B3one mark for each correct nibble, in the correct order
3(a)(ii)2607B1
3(b)(i)1 · 9 · BB3one mark for each correct character, in order
3(b)(ii)411B1
3(c)Any one: easier / quicker to read / understand / debug · shorter representation of binary // less screen spaceB1
3(d)Any two: HTML colour codes · URL · memory dump · IP address · MAC address · assembly language · error codes · ASCII / UnicodeB2
Total: 11 marks
0478/12/M/J/25 Q1Paper 1 · Computer systems5 marksFull size
Add 01100101 and 01110000; explain overflow

How to start Set out the carry row first. For (f), give two separate facts: the size of the result and the size of the register.

Show a full-mark answer and the mark scheme
1286432168421
Carry11
01100101
+01110000
Answer11010101

(e) 1101 0101 (101 + 112 = 213, so no overflow here).

(f) The result is greater than 255, so it is too large for the register. It would need more than 8 bits, but the register only has 8.

PartAnswer / workingMarksGuidance
1(e)1101 0101B2one mark for each correct nibble
1(e)correct method of working, e.g. showing carriesM1
1(f)Any two: the result is greater than 255 // too large · cannot be stored in 8 bits // in the bits available for the registerB2
Total: 5 marks
0478/13/O/N/24 Q1Paper 1 · Computer systems4 marksFull size
Add 11100011 and 11001100 (the answer overflows)

How to start Two big numbers (both start with 11): expect a carry out of the last column. Show it as a 9th bit.

Show a full-mark answer and the mark scheme
OF1286432168421
Carry11
11100011
+11001100
Answer110101111

1 1010 1111: the 9th bit is an overflow (227 + 204 = 431, more than 255).

PartAnswer / workingMarksGuidance
1(d)1010 1111B2one mark for each correct nibble
1(d)method of working, e.g. carriesM1
1(d)identification of overflow (the extra 1)B1
Total: 4 marks

Examiner tip The overflow bit earns its own mark: write it, and label it.

Common mistakes

  • ✗ "Hex takes up less memory"✓ "Hex is shorter / easier for humans to read"The computer stores binary either way.
  • ✗ Leaving out the carries✓ A carry row above the sumThe working mark is for the carries.
  • ✗ Dropping the 9th bit silently✓ Write the extra 1 and label it overflowThere is a mark for identifying the overflow.
  • ✗ "Overflow is when the number is too small / negative"✓ "Too large for the number of bits available"

Practice

Practice: easy, medium, hard

Easy

1
Add 0001 0101 and 0010 0110.
Show working
  1. 21 + 38 = 59

Answer 0011 1011

2
Give one use of hexadecimal.
Show answer

Answer e.g. HTML colour codes / MAC addresses / error codes

3
What is the largest denary value an 8-bit register can store?
Show answer

Answer 255

Medium

1
Add 0111 0110 and 0011 0000.
Show working
  1. 118 + 48 = 166

Answer 1010 0110

2
Give two reasons why hex is used instead of binary to display error codes.
Show answer

Answer Shorter / takes less screen space; easier to read and remember; fewer mistakes when copying

3
An HTML colour is #8000FF. Give the denary amount of red (the first two digits).
Show working
  1. 80 = 8 × 16 = 128

Answer 128

Hard

1
Add 1011 1101 and 0110 0110. Explain what happens in an 8-bit register.
Show working
  1. 189 + 102 = 291
  2. 9 bits needed

Answer 1 0010 0011: overflow, because 189 + 102 = 291 > 255 and the 9th bit is lost

PartAnswer / workingMarksGuidance
1 0010 0011 (each nibble)B2
carries shownM1
overflow identifiedB1
Total: 4 marks
2
A memory dump shows the address 0FC8. Give it in binary and in denary.
Show working
  1. 0 = 0000, F = 1111, C = 1100, 8 = 1000
  2. 15 × 256 + 12 × 16 + 8 = 3840 + 192 + 8 = 4040

Answer 0000 1111 1100 1000 · 4040

Can I do this?

Anything unticked: revise that section first. All ticked: take the quiz.

Quiz

The multiple-choice and guided questions need JavaScript. The concept checks and exam practice below work without it.

Your progress on this note is saved when JavaScript is on.

⬇️ Download this chapter as a PDF: Full notes