Create your own
Lesson illustration

Converting Between Binary, Denary, and Hexadecimal

Hello. The previous lesson used numbers to describe physical motion; this lesson shifts to how a computer stores and displays numbers. The quantity does not change when its representation changes: , , and all mean the same value, written in three different number systems.

This is the Computer Science part of the current foundations module. By the end, you should be able to convert positive integers reliably between denary (base ), binary (base ), and hexadecimal (base ), showing working in an exam-ready way.


One idea behind every number system: place value

We normally write numbers in denary, also called decimal. Denary is base , meaning it has ten possible digits:

The value of each digit depends on its position. For example:

Each place value is ten times the value of the place to its right.

Binary and hexadecimal use exactly the same place-value principle, but their place values increase by different factors.

SystemBaseSymbols availablePlace values from right to left
Denary to
Binary
Hexadecimal to , to

A base tells you two things:

  1. which symbols are legal in that system;
  2. how much each place is worth compared with the place on its right.

So is not valid binary because binary has no digit . Similarly, is not valid hexadecimal because hexadecimal ends at .

Use base labels whenever a number could be ambiguous:

The left value is binary and means ten in denary; the right value means one thousand and ten.

Binary, Hexadecimal, and Decimal Conversion – Simple Explanation | Basic Electronics

Watch "Binary, Hexadecimal, and Decimal Conversion - Simple Explanation" from CircuitBread for a visual walkthrough of base-two place values, denary-to-binary conversion, hexadecimal notation, and four-bit grouping.

Skip the general introduction and begin with binary place values. Then watch denary to binary, paying attention to the repeated subtraction from the largest suitable power of two. Continue with hexadecimal basics for base-16 place values and the meanings of A to F. Finish with four bit groups, which explains why binary and hexadecimal convert so neatly.


Binary and denary

A bit is one binary digit. Its only possible values are and . In a positive binary integer, a means “include this place value” and a means “do not include it.”

For eight bits, write the place values above the binary number:

Place value
Binary digit

Therefore:

Converting binary to denary

Use this method:

  1. Write the binary place values.
  2. Select the values with a underneath them.
  3. Add those selected values.

For example:

The bits represent , , , and :

The leading zero does not alter the value. However, do not casually remove leading zeros if a question specifies a fixed number of bits. In an eight-bit representation, makes it clear that the number occupies one byte.

A byte is eight bits. The smallest unsigned value in one byte is:

The largest is:

This range, from to , is important in later data-representation topics.

Converting denary to binary

The most reliable exam method is to work from the largest available binary place value downwards. For each value, decide whether it can be subtracted from the remaining denary number.

Example: Convert to eight-bit binary.

The place values are:

Start with .

  • , so the bit is .
  • is less than , so the bit is .
  • , so the bit is .
  • is less than , so the bit is .
  • , so the bit is .
  • , so the bit is .
  • is less than , so the bit is .
  • , so the bit is .

The resulting bits are:

Check by converting back:

This reverse check is quick and catches many mistakes.

The left table matches each four-bit binary pattern from \(0000\) to \(1111\) with its denary and hexadecimal value; the right table shows the \(128\) to \(1\) place values used to decode an eight-bit binary number.

Hexadecimal: a compact way to write binary

Long strings of binary are difficult for people to read and copy accurately. Hexadecimal, usually shortened to hex, gives us a convenient shorthand.

Hex is base , so it needs sixteen symbols:

Denary value to
Hex symbol to

It is essential to memorise:

After , hexadecimal carries into a new place:

This does not mean that has value ten. It means:

Hexadecimal - Units and data representation - OCR - GCSE Computer Science Revision - Cambridge OCR - BBC Bitesize

Read BBC Bitesize's "Hexadecimal" page for a compact reference table showing the denary, binary, and hexadecimal values from 0 to 15.

On the page titled "Hexadecimal", read from the opening explanation of number bases through the table and its short explanation of why hex is useful. Use the reference table to consolidate the A-to-F values. Focus particularly on the one-to-one correspondence between one hexadecimal digit and four binary bits.

Converting hexadecimal to denary

Hexadecimal place values are powers of :

For a two-digit hex number, multiply the left digit by , add the right digit, and remember to convert letters to their denary values first.

Example: Convert to denary.

Since :

For three hex digits, the place values are , , and .

For example:

Converting denary to hexadecimal

For values below , divide by . The quotient becomes the first hex digit, and the remainder becomes the second.

Example: Convert to hexadecimal.

In hex:

Therefore:

Check:

For larger denary values, repeat division by until the quotient is zero. Record each remainder, then read the remainders from the last one obtained back to the first.


The fastest conversion: binary and hexadecimal

Binary and hexadecimal have a special relationship:

Four bits can represent exactly different values, from to . That is exactly the number of symbols available in hexadecimal.

A group of four bits is called a nibble. One hex digit represents one nibble.

Converting binary to hexadecimal

  1. Starting at the right, split the binary number into groups of four bits.
  2. Add zeros on the left if the leftmost group has fewer than four bits.
  3. Convert each four-bit group into one hex digit.

Example: Convert to hex.

Split the bits:

The first group has value , which is . The second group has value .

This agrees with the earlier conversion:

Example with padding:

Pad on the left:

Each group is , so:

Converting hexadecimal to binary

Replace each hex digit with its four-bit binary pattern. Keep all four bits, including zeros.

Hex digitFour-bit binary

For example:

And:

Two hexadecimal digits therefore describe exactly one byte:

This is why hexadecimal appears in places such as colour codes and hardware addresses: it is much shorter than binary but maps to binary without complicated arithmetic.


Choosing a method and avoiding mistakes

Use the method that suits the starting and target forms.

Starting formTarget formReliable method
BinaryDenaryAdd the selected powers of
DenaryBinaryWork down through powers of , subtracting where possible
HexadecimalDenaryMultiply each digit by its power of , then add
DenaryHexadecimalDivide repeatedly by , using remainders
BinaryHexadecimalGroup into nibbles from the right
HexadecimalBinaryReplace every hex digit with four bits

The most common errors are not difficult calculations; they are interpretation errors.

MistakeCorrect principle
Treating as a letter rather than a value represents , represents , through to
Writing
Grouping binary from the leftAlways form groups of four from the right, then pad on the left if needed
Forgetting a zero in hex-to-binary conversionEvery hex digit must be replaced by exactly four bits
Adding all binary place valuesAdd only the place values whose bits are
Giving an answer without stating its baseUse words or subscripts when ambiguity is possible

For an O Level conversion question, make your working visible. A short place-value table, a subtraction trail, or grouped nibbles can earn method credit and makes your final answer easier to check.


Key takeaways

Denary, binary, and hexadecimal are all place-value systems:

  • denary is base ;
  • binary is base , using only and ;
  • hexadecimal is base , using to and to .

To decode binary, add the powers of with a bit. To encode a denary number in binary, work from the largest useful power of downwards.

In hexadecimal:

The key shortcut is that one hex digit equals four binary bits. Group binary into nibbles to obtain hex, or replace every hex digit with a four-bit pattern to obtain binary.

The next Computer Science lesson builds directly on this representation work: you will perform binary addition and logical shifts, including identifying overflow in fixed-length binary values.

Can't find a good explanation? Sign up and we'll make it for you

Sign up