KS41CP2 2.1 28 min read 10 question quiz 16 exam marks

Binary and Hexadecimal

Why a computer has only two digits to work with, how to convert in both directions without a calculator, and what hexadecimal is actually for.

Why binary

A computer stores and processes everything as binary, a number system with only two digits, 0 and 1. This is not a design preference, it is a consequence of the hardware.

Inside a computer, data is held as an electrical state: a transistor conducting or not conducting, a capacitor charged or discharged, a region of a disc magnetised one way or the other. Each of those is a two state device, so it can represent exactly two values. Call them 0 and 1 and you have binary.

Why not ten states instead

You could in principle build a component with ten distinguishable voltage levels and use denary directly. It would be a bad idea. Two states can be told apart even when the signal is noisy or the voltage drifts, because anything below a threshold reads as 0 and anything above it reads as 1. Ten states would need nine thresholds packed into the same voltage range, so a small amount of electrical interference would produce a wrong value. Binary is used because it is reliable, cheap to manufacture and easy to design circuits for.

The vocabulary

  • A bit is a single binary digit, a 0 or a 1.
  • A nibble is 4 bits.
  • A byte is 8 bits.

An 8 bit binary number can represent 2 to the power 8, that is 256, different values, so as an unsigned integer it covers 0 to 255.

The exam sentence

Computers use binary because the components they are built from have two stable states, on and off, and binary digits map directly onto those states, which makes the circuits reliable and simple.

Converting between denary and binary

Place values

An 8 bit binary number has these place values, each double the one to its right:

1286432168421
11001010

Binary to denary

Add up the place values wherever there is a 1. For 11001010: 128 + 64 + 8 + 2 = 202.

Write the place values above the digits before you start. Every mark lost on this question is lost by someone who tried to do it from memory and slipped a column.

Denary to binary

Work from the largest place value down, asking one question at a time: does this fit into what is left?

Converting 202:

Place valueDoes it fit into what remains?BitRemaining
128128 fits into 202174
6464 fits into 74110
3232 does not fit into 10010
1616 does not fit into 10010
88 fits into 1012
44 does not fit into 202
22 fits into 210
11 does not fit into 000

The answer is 11001010. The remainder reaching zero exactly is your check that you have not made an error.

Pad to eight bits

If the question says 8 bit, write all eight digits. 1010 is a correct value but an incomplete answer; write 00001010.

Converting binary 01011010 to denary using place valuesAn eight bit binary number laid out under its place values. The place values from left to right are 128, 64, 32, 16, 8, 4, 2 and 1, each half the one to its left. The bits are 0, 1, 0, 1, 1, 0, 1, 0. Where a bit is 1 the column contributes its place value, so the contributions are 0, 64, 0, 16, 8, 0, 2 and 0. Adding the contributions gives 64 plus 16 plus 8 plus 2, which is 90. So binary 01011010 is 90 in denary.1280064164320016116818400212100placebitworth64 + 16 + 8 + 2 = 90so 01011010 in binary is 90 in denary
Write the place values above the bits every single time. It costs five seconds and removes almost every conversion error.

Number base converter

Convert between denary, binary and hexadecimal, with every step of the working written out. This tool needs JavaScript, so turn it on to use it. Everything you need to answer the exam question is explained in the text above.

The eight place value columns of a byte, here holding 0101 1010The eight place value columns of a byte, drawn as blocks whose height is the value of the column: 128, 64, 32, 16, 8, 4, 2 and 1 from left to right, each one worth double the column to its right. Above each column is a light that is on for a 1 and off for a 0. To read a binary number, take the value of every column holding a 1 and ignore every column holding a 0. For 0101 1010 that means taking 64, 16, 8 and 2, which add up to 90. The tallest block shows something worth remembering: the leftmost column, 128, is worth more than all of the other seven added together, which come to 127.0128skip164032skip1161804skip1201skipa 1 means take the column, a 0 means skip it128 is worth more than all the rest together (127)64 + 16 + 8 + 2 = 901234
  1. Eight columns, and each one is worth double the one to its right.
  2. A 1 means take that column's value. A 0 means skip it.
  3. Add up the columns you took: 64 + 16 + 8 + 2 = 90.
  4. The leftmost bit is worth more than every other bit added together.
Each column doubles. Learn the row 128 64 32 16 8 4 2 1 and every conversion question becomes adding up.

Hexadecimal

Hexadecimal, or hex, is base 16. It uses the digits 0 to 9 and then the letters A to F for the values 10 to 15.

Denary101112131415
HexABCDEF

Why it exists

Hex is not used because computers understand it. They do not: everything is still binary underneath. Hex exists because people make mistakes reading long strings of 0s and 1s.

The number 11001010 is easy to mistype, hard to say out loud and difficult to compare with a similar value at a glance. The same number in hex is CA, two characters. The conversion works because one hex digit represents exactly four bits, so any binary number can be split into nibbles and translated straight across with no arithmetic.

This is why hex is used for MAC addresses, colour codes in web design, memory addresses and machine code listings.

Binary to hex

Split into nibbles of four bits from the right, then convert each nibble.

11001010 splits into 1100 and 1010. 1100 is 8 + 4 = 12, which is C. 1010 is 8 + 2 = 10, which is A. The answer is CA.

Hex to binary

Convert each digit into four bits. 2F becomes 0010 and 1111, so 00101111.

Hex to denary

Multiply the left digit by 16 and add the right digit. CA is (12 multiplied by 16) plus 10, which is 192 + 10 = 202. 2F is (2 multiplied by 16) plus 15 = 47.

Denary to hex

The safe route is through binary: convert to 8 bit binary, split into two nibbles, convert each. Converting 181 directly is error prone, but 181 is 10110101, which splits into 1011 and 0101, giving B5.

Route your conversions through binary

In an exam, denary to hex and hex to denary are both quicker and safer via binary, because you already know the place values cold and there is no multiplication to slip up on.

Converting 1010 1111 to hexadecimal one nibble at a time, and the sixteen hex digitsHow to convert a byte to hexadecimal. The byte 1010 1111 is split into two nibbles of four bits each: 1010 on the left and 1111 on the right. Each nibble is converted on its own using the place values 8, 4, 2 and 1. The left nibble is 8 plus 2, which is 10, and 10 is the hex digit A. The right nibble is 8 plus 4 plus 2 plus 1, which is 15, and 15 is the hex digit F. Written side by side the byte is AF in hex. Underneath is a table of all sixteen hex digits with their denary and four bit binary values: 0 to 9 are written as themselves and 10 to 15 are written A, B, C, D, E and F.Binary to hex, one nibble at a time101011118 + 2 = 10A8 + 4 + 2 + 1 = 15FAFside by sideThe sixteen hex digitshexdenarybinary000000110001220010330011440100550101660110770111881000991001A101010B111011C121100D131101E141110F151111One hex digit is always exactly four bits.1234
  1. Split the byte into two nibbles of four bits. Colours keep each nibble with its digit.
  2. Convert each nibble on its own with 8, 4, 2 and 1: 1010 is 10 and 1111 is 15.
  3. Write each value as one hex digit, 10 as A and 15 as F, and put them side by side.
  4. Learn the table: 0 to 9 look the same in hex, then A is 10 up to F which is 15.
Split into nibbles, convert each, join them up. Going the other way, turn each hex digit back into four bits.

Key terms you must be able to define

Binary
A number system with base 2 that uses only the digits 0 and 1.
Bit
A single binary digit, either 0 or 1, and the smallest unit of data a computer can store.
Nibble
A group of four bits, which is exactly the amount represented by one hexadecimal digit.
Byte
A group of eight bits, able to represent 256 different values.
Denary
The everyday number system with base 10, using the digits 0 to 9.
Hexadecimal
A number system with base 16 that uses the digits 0 to 9 and the letters A to F.
Place value
The value a digit represents because of its position, doubling with each move to the left in binary.
Unsigned integer
A whole number with no sign bit, so an 8 bit unsigned integer represents values from 0 to 255.
Most significant bit
The leftmost bit of a binary number, which carries the largest place value.

Flashcards

Say the definition out loud before you flip the card. Retrieving it from memory is what builds recall, reading it again is not.

DefineBinary
AnswerA number system with base 2 that uses only the digits 0 and 1.
DefineBit
AnswerA single binary digit, either 0 or 1, and the smallest unit of data a computer can store.
DefineNibble
AnswerA group of four bits, which is exactly the amount represented by one hexadecimal digit.
DefineByte
AnswerA group of eight bits, able to represent 256 different values.
DefineDenary
AnswerThe everyday number system with base 10, using the digits 0 to 9.
DefineHexadecimal
AnswerA number system with base 16 that uses the digits 0 to 9 and the letters A to F.
DefinePlace value
AnswerThe value a digit represents because of its position, doubling with each move to the left in binary.
DefineUnsigned integer
AnswerA whole number with no sign bit, so an 8 bit unsigned integer represents values from 0 to 255.

Reach the top grade on this topic

Conversions are marked right or wrong, so accuracy under pressure is the whole skill.

Write the place values down every time. Every single time, even when you are sure. It costs four seconds and it is the difference between 202 and 234.

Check your answer by converting it back. If you convert 181 to 10110101, add up 128 + 32 + 16 + 4 + 1 and confirm you get 181. Two conversions take less than a minute and turn a guess into a certainty.

Explain hexadecimal in terms of people, not machines. The reason hex exists is that humans read and write it more reliably than binary, and one hex digit maps to exactly four bits so the translation needs no calculation. An answer claiming that computers use hex, or that hex saves storage space, is wrong: the value in memory is identical.

Be precise about ranges. An 8 bit unsigned value covers 0 to 255, which is 256 different values. Saying "up to 256" is the classic slip.

  • Be able to convert any denary value from 0 to 255 into 8 bit binary in under thirty seconds
  • Be able to convert 8 bit binary to denary and to hexadecimal
  • Be able to convert two hexadecimal digits to binary and to denary
  • Be able to give three real uses of hexadecimal and explain why hex rather than binary is used there

Mistakes that cost marks here

Avoid these
  • Reading binary place values from the left as 1, 2, 4, 8. The place values increase from right to left, so the leftmost bit of a byte is 128.
  • Giving a binary answer with fewer than eight bits when the question specifies an 8 bit number.
  • Saying computers use hexadecimal. Computers use binary. Hex is a shorthand for people reading and writing binary values.
  • Claiming hexadecimal saves memory. CA and 11001010 occupy exactly the same eight bits in the machine.
  • Saying an 8 bit unsigned number can store values up to 256. It stores 256 different values, from 0 to 255.
  • Splitting binary into nibbles from the left rather than the right, which gives the wrong answer whenever the number has fewer than eight digits.
Fun fact

A single hexadecimal digit represents exactly four bits, which is why hex is used for colour codes and MAC addresses. The colour written as FF8000 is 11111111 10000000 00000000 in binary, which is why nobody writes colours in binary.

Knowledge check

0 of 10 answered
1What is 11001010 in denary?
2What is 181 in 8 bit binary?
3Why do computers use binary rather than denary?
4How many bits are represented by a single hexadecimal digit?
5What is the hexadecimal equivalent of the binary number 10110101?
6What is 2F in denary?
7How many different values can be represented by one byte?
8Which statement about hexadecimal is correct?
9What is the largest value that can be stored in a nibble?
10Which of these is a genuine use of hexadecimal?
Score 0 / 10

Exam-style questions

Five written questions in the style of the real paper. Write a full answer, then let the marker check it against the mark scheme.

16 marks
1Convert the denary number 156 into an 8 bit binary number. Show your working.2 marks
Calculate

Mark scheme0 / 2
  • LCorrect binary answer 10011100
  • LWorking shown using place values, subtracting 128, 16, 8 and 4
Model answer

Starting from the highest place value, 128 fits into 156 and leaves 28, so the first bit is 1. 64 does not fit into 28 and 32 does not fit into 28, so the next two bits are 0. 16 fits into 28 and leaves 12, 8 fits into 12 and leaves 4, and 4 fits into 4 and leaves 0, so those three bits are 1. The final two place values, 2 and 1, do not fit into 0, so both are 0. The answer is 10011100.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
2Explain why computers represent all data in binary.3 marks
Explain

Mark scheme0 / 3
  • LComputer components such as transistors have two states, on and off
  • LThese two states map directly onto the digits 0 and 1
  • LTwo states can be distinguished reliably even with electrical noise, so circuits are simpler and less error prone
Model answer

The components a computer is built from, such as transistors and memory cells, are two state devices: they are either conducting or not conducting, charged or discharged. Those two states map directly onto the two digits of binary, 0 and 1, so no translation is needed between the data and the hardware holding it. Two states are used rather than ten because a circuit only has to distinguish between a voltage above a threshold and one below it, which remains reliable even when the signal is affected by electrical noise or by voltage drifting slightly, and circuits that only have to make that one distinction are simpler and cheaper to manufacture.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
3Convert the binary number 11100101 into hexadecimal and into denary.4 marks
Calculate

Mark scheme0 / 4
  • LSplits the binary number into the nibbles 1110 and 0101
  • LCorrectly gives the hexadecimal answer E5
  • LAdds the place values 128, 64, 32, 4 and 1
  • LCorrectly gives the denary answer 229
Model answer

To convert to hexadecimal the byte is split into two nibbles from the right, giving 1110 and 0101. The nibble 1110 is 8 plus 4 plus 2, which is 14, and 14 is written as E in hexadecimal. The nibble 0101 is 4 plus 1, which is 5. The hexadecimal value is therefore E5. To convert to denary the place values where a 1 appears are added together: 128 plus 64 plus 32 plus 4 plus 1, which gives 229. This can be checked against the hexadecimal answer, since E is 14 and 14 multiplied by 16 is 224, and 224 plus 5 is 229.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
4Explain why hexadecimal is used by programmers when working with binary data.4 marks
Explain

Mark scheme0 / 4
  • LOne hexadecimal digit represents exactly four bits
  • LSo binary values can be written far more briefly, two digits instead of eight
  • LShorter values are easier for people to read, write, remember and compare, so fewer mistakes are made
  • LConversion between hexadecimal and binary is direct and requires no calculation
Model answer

Hexadecimal is base 16, and because 16 is 2 to the power 4, one hexadecimal digit represents exactly four bits. That relationship means a byte can always be written as two hexadecimal digits, so a value such as 11001010 becomes simply CA. Programmers work with binary values constantly, in memory addresses, colour codes and MAC addresses, and long strings of ones and zeros are extremely easy to misread, mistype or lose your place in. Writing the same value in a quarter of the characters makes it far easier to read aloud, note down and compare with another value. The conversion is also completely mechanical: each group of four bits translates straight into one hexadecimal digit with no arithmetic at all, so nothing is lost or risked in moving between the two.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
5A student claims that storing a value in hexadecimal saves memory compared with storing it in binary. Explain why this claim is incorrect.3 marks
Explain

Mark scheme0 / 3
  • LAll data is stored in the computer as binary regardless of how it is written down
  • LHexadecimal is a way of writing or displaying a value for people, not a way of storing it
  • LThe value CA and the value 11001010 occupy the same eight bits in memory
Model answer

The claim is incorrect because every value inside a computer is held as binary, whatever notation a person uses when writing it down. Hexadecimal is a human readable shorthand for binary, not a separate storage format, so writing a byte as CA rather than as 11001010 changes nothing about the memory the value occupies. Both notations describe the same eight bits, and those eight bits take up one byte of memory in either case. What hexadecimal saves is not space in the machine but effort and errors for the person reading and writing the value.

The marker looks for key phrases. If you said it another way and it is still right, give yourself the mark.
Machine mark 0 / 16