Binary, denary and hexadecimal

GCSE Computer Science (OCR) · OCR J277 · Computer systems (Paper 1) › Memory and storage › Data storage

63 exam-style questions plus unlimited generated ones on this topic, at up to four difficulty levels, with full mark schemes. Notes and past-paper booklets are open to everyone. Practice needs a free account.

Or take a quick quiz: 11 questions on this subtopic in GCSE Computer Science (OCR), marked as you tap.

Revision notes

Converting positive whole numbers between denary (base 10), binary (base 2) and hexadecimal (base 16), within the J277 range: denary 0 to 255, binary up to 8 bits and hexadecimal 00 to FF. These are quick, reliable marks on Paper 1 once you have practised the methods by hand.

Key facts

  • 8-bit place values: 128 64 32 16 8 4 2 1
  • 8 bits: 0 to 255 (256 values); n bits: 2n values
  • Hex digits: 0⁠–⁠9, A = 10, B = 11, C = 12, D = 13, E = 14, F = 15
  • Hex → denary: first digit × 16 + second digit
  • Denary → hex: ÷ 16; the whole number is the first digit, the remainder is the second
  • 1 hex digit = 4 bits (a nibble); nibble place values 8 4 2 1
  • FF = 255 = 11111111; 00 = 0 = 00000000
  • MSB = left-most bit; LSB = right-most bit

Notes

Binary and denary

diagram
  • Denary is base 10 (digits 0 to 9); binary is base 2 (only 0 and 1).
  • 8-bit place values: 128 64 32 16 8 4 2 1.
  • The left-most bit is the most significant bit (MSB); the right-most bit is the least significant bit (LSB).
  • Binary → denary: add the place values of the columns holding a 1. E.g. 01011010 = 64 + 16 + 8 + 2 = 90.
  • Denary → binary: start at 128. If the number is at least the place value, write 1 and subtract; otherwise write 0. Move right and repeat. E.g. 150 = 128 + 16 + 4 + 2 = 10010110.
  • 128164032016180412110128 + 16 + 4 + 2 = 150
    150 in binary: a 1 goes under each place value used
  • 8 bits can hold 256 different values, from 0 (00000000) to 255 (11111111). In general, n bits give 2n different values. Grade 7+ only

Hexadecimal

  • Hexadecimal (base 16) uses the digits 0 to 9 and then A = 10, B = 11, C = 12, D = 13, E = 14, F = 15.
  • A 2-digit hex number has place values 16 and 1. The largest is FF = 15 × 16 + 15 = 255.
  • Hex → denary: first digit × 16 + second digit. E.g. 7C = 7 × 16 + 12 = 112 + 12 = 124.
  • Denary → hex: divide by 16. The whole number of 16s is the first digit and the remainder is the second. E.g. 203 ÷ 16 = 12 remainder 11, so 203 = CB.

Binary and hexadecimal

diagram
  • One hex digit represents exactly 4 bits (a nibble), because 4 bits give 24 = 16 patterns.
  • Binary → hex: split the bits into nibbles from the right and convert each one using 8 4 2 1. E.g. 1101 0110 → 13 and 6 → D6.
  • 81412011804121108 + 4 + 1 = 13 = D4 + 2 = 611010110 = D6
    Split into nibbles, convert each with 8 4 2 1, then write each as one hex digit
  • Hex → binary: write each digit as 4 bits. E.g. 3E → 0011 and 1110 → 00111110.
  • If a binary number has fewer than 8 bits, add 0s on the left, never on the right.
  • Hex is used because it is shorter than binary and easier for people to read, remember and type, so fewer mistakes are made. It also converts easily to and from binary.

How to answer each type of question

M = method mark, A = answer mark, B = a mark on its own.

Convert between binary and denary

1 mark eachGrade 4
  1. Write the place values 128 to 1 above the bits.
  2. Binary to denary: add the values above each 1.
  3. Denary to binary: subtract the largest place value you can, working left to right, and give all 8 bits.
  4. Check by converting your answer back.

Example. (a) Convert the binary number 10100011 into denary. [1]
(b) Convert the denary number 77 into 8-bit binary. [1]

Show the model answerHide the model answer
(a) 128 + 32 + 2 + 1 = 163
(1)
(b) 77 = 64 + 8 + 4 + 1, so 01001101
(1)

Convert between hexadecimal and binary

1 to 2 marksGrade 5
  1. Hex to binary: write each hex digit as a 4-bit nibble.
  2. Binary to hex: split into nibbles from the right, convert each using 8 4 2 1, and write 10 to 15 as A to F.

Example. (a) Convert the hexadecimal number A7 into 8-bit binary. [2]
(b) Convert the binary number 00111011 into hexadecimal. [1]

Show the model answerHide the model answer
(a) A = 1010 (1) and 7 = 0111 (1), so 10100111
(b) 0011 = 3 and 1011 = 11 = B, so 3B
(1)

Convert between denary and hexadecimal, showing working

2 marks eachGrade 6
  1. Hex to denary: multiply the first digit by 16, then add the second digit.
  2. Denary to hex: divide by 16; write the quotient and the remainder as hex digits.
  3. Or go via binary if you find that easier.

Example. (a) Convert the hexadecimal number 5E into denary. Show your working. [2]
(b) Convert the denary number 180 into hexadecimal. Show your working. [2]

Show the model answerHide the model answer
(a) 5 × 16 = 80 and E = 14 (1); 80 + 14 = 94
(1)
(b) 180 ÷ 16 = 11 remainder 4 (1); 11 = B, so B4
(1)

Explain why hexadecimal is used

2 marksGrade 6
  1. Give a reason about length: one hex digit replaces four bits.
  2. Give a reason about people: easier to read, remember and type, so fewer errors.
  3. Remember that the computer still stores the value in binary.

Example. A programmer views the contents of memory in hexadecimal rather than binary. Explain two reasons why. [2]

Show the model answerHide the model answer
Hexadecimal is shorter because one hex digit represents four bits, so values are quicker to read and write (1). It is easier for people to read and remember, so fewer mistakes are made when copying values (1). Also accept: it is easy to convert between hexadecimal and binary.

Don’t lose marks

  • Writing the bits in reverse order, with the least significant bit on the left.
  • Giving fewer than 8 bits when 8-bit binary is asked for. Add leading zeros.
  • Grouping bits into nibbles from the left when there are fewer than 8 bits. Always group from the right.
  • Writing 1011 as '11' in hex instead of B.
  • In hex to denary, multiplying the second digit by 16 instead of the first.

More tips

Memory tricks

  • Hex letters: A is 10, then count up: A10, B11, C12, D13, E14, F15.
  • Denary to hex the easy way: go via binary. 180 → 1011 0100 → B4.
  • Quick checks: odd denary numbers end in 1 in binary; any number of 128 or more starts with 1 in 8 bits.
  • Learn the 16 nibbles (0000 = 0 up to 1111 = F) and hex conversions become instant.

Exam technique

  • Write the place values (128 … 1) on the paper before converting: it takes seconds and prevents slips.
  • Show your working (place values, the ÷ 16 step): 2-mark conversions often give a method mark.
  • Check each answer by converting it back the other way.
  • Paper 1 is non-calculator, so practise conversions by hand until they are automatic.

What each grade needs

What you need to be able to do, from the first marks up to the top grade.

  1. Grade 3
    Convert 8-bit binary to denaryAdd the place values (128, 64, 32, 16, 8, 4, 2, 1) of every column that holds a 1.
  2. Grade 4
    Convert denary to 8-bit binaryWork from 128 downwards, putting a 1 in each column whose value you can subtract.
  3. Grade 4
    Identify the most and least significant bitsThe most significant bit is the left-most bit (worth 128 in 8 bits); the least significant bit is the right-most (worth 1).
  4. Grade 5
    Convert between binary and hexadecimalSplit the 8 bits into two nibbles; each nibble is one hex digit from 0 to F.
  5. Grade 6
    Convert between denary and hexadecimalHex to denary: first digit × 16 + second digit; denary to hex: divide by 16 and use the remainder.
  6. Grade 6
    Explain why hexadecimal is usedIt is shorter and easier for people to read and write than binary, so fewer mistakes are made, and it converts easily.
  7. Grade 7
    Reason about ranges and bit patternsE.g. n bits give 2n values, odd numbers end in 1, and why each hex digit matches exactly four bits.

Quick recall

Cover the answers and test yourself. The app has these as flashcards that come back just before you'd forget them.

State the denary place value of the most significant bit in an 8-bit binary number.
128
State the largest 2-digit hexadecimal number and give its denary value.
FF = 255
State how many bits are needed to represent one hexadecimal digit.
4
State the number of different digits (symbols) used in the hexadecimal number system.
16
Hexadecimal uses letters as well as digits. State the denary value of the hexadecimal digit E.
14
Write these hexadecimal digits in order of value, smallest first.
D, 7, A, 2
2, 7, A, D

Sample questions

Written for this site in the style of OCR exam questions. They are not taken from real past papers.

Question 1Easy3 marks
(a) State the denary place value of the most significant bit in an 8-bit binary number.
[1]
(b) Convert the binary number 00101101 into denary.
[1]
(c) State the largest denary number that can be represented using 8 bits.
[1]
Show the answer and mark scheme
(a) Answer: 128
  • 128
(b) Answer: 45
  • 45
(c) Answer: 255
  • 255
Question 2Medium3 marks
(a) Explain why hexadecimal is often used to represent binary values.
[2]
(b) Give one example of where hexadecimal is used in computing.
[1]
Show the answer and mark scheme
(a)
  • hexadecimal is shorter / uses fewer digits (one hex digit for every four bits)
  • it is easier for humans to read, remember and write
  • fewer mistakes are made when copying or typing it
  • it is easy to convert between hexadecimal and binary
(b)
  • colour codes (e.g. in HTML / CSS) / MAC addresses / IPv6 addresses / memory addresses / error codes
Question 3Hard4 marks
(a) Explain why each hexadecimal digit can be represented by exactly four binary digits.
[2]
(b) Convert the binary number 1011100 into hexadecimal.
Show your working.
[2]
Show the answer and mark scheme
(a)
  • there are 16 hexadecimal digits (0 to 9 and A to F)
  • four bits give 24 = 16 different patterns, so each hex digit matches exactly one 4-bit pattern (nibble)
(b) Answer: 5C
  • splits the bits into groups of four from the right / writes it as 8 bits: 0101 1100
  • 5C

More in Data storage

Stuck? Get 1-to-1 help.

Chhetri Academy tutors GCSE and A level Maths and Science online, with a free 30-minute trial lesson.