HelpContactFor teachers and institutes
>_StemPy Lab
Mock TestsClasses

>_StemPy Lab

Learn. Solve. Code the solutions. Test yourself.

Live examsFree mock exams, timed and rankedEveryone starts together, and your score and rank come the moment it ends.See the exams →

Learn

  • Physics
  • Chemistry
  • Mathematics
  • Biology
  • Python Programming
  • Statistics & Data Science
  • Computer Science
  • Classes
  • Groups

Practice

  • Problems
  • Quizzes
  • Mock Tests
  • Prepare for an Exam
  • Question Sets
  • Exams
  • Certificates
  • Python Labs
  • AI Practice Generator
  • Student-Created Tests

Community

  • Discussions
  • Resources
  • Notes
  • Glossary
  • Blog

Account

  • Log in
© 2026 senLearn. All rights reserved.HelpFor SchoolsAboutContactPrivacy PolicyTerms of UseRefund Policy
Binary, Denary and Hexadecimal
  1. 1Binary and denary
  2. 2Hexadecimal and why we use it
  3. 3Binary addition, overflow, shifts and two's complement
  1. Computer Science
  2. /Binary, Denary and Hexadecimal
  3. /Hexadecimal and why we use it

Course 1.1·Lesson 2 of 3

Hexadecimal and why we use it

Hexadecimal is the base 16 number system. One hexadecimal digit stands for four bits, so long binary numbers become short and easy to read. You convert between hexadecimal, binary and denary, and learn where computer scientists use hexadecimal.

about 25 min1 simulation1 practice question
Lesson 2 of 3Show all lessonsHide
Binary, Denary and Hexadecimal
  1. 1Binary and denary
  2. 2Hexadecimal and why we use it
  3. 3Binary addition, overflow, shifts and two's complement

Try the code and the simulations beside the lesson.

Sixteen digits

Look at the binary number 1011010011110010. It is hard to read, and very easy to copy wrongly. Hexadecimal (hex for short) writes the same number as B4F2. It is much shorter.

Hexadecimal is the base 16 system. It needs sixteen digits. It uses 0 to 9, and then the letters A to F for the values ten to fifteen.

  • A is 10, B is 11 and C is 12.
  • D is 13, E is 14 and F is 15.

Each place in hexadecimal is worth 16 times the place to its right. A two-digit hex number has the place values 16 and 1. A four-digit one has 4096, 256, 16 and 1.

One hex digit is four bits

Four bits can hold 0000 to 1111, which is 0 to 15. That is exactly one hexadecimal digit. A group of four bits is called a nibble. So one byte is two nibbles, and two hex digits.

A table of the sixteen nibbles in two halves. Each row gives a 4-bit pattern, its denary value and its hexadecimal digit: 0000 is 0 and 0, 0001 is 1 and 1, and so on up to 1001 is 9 and 9, then 1010 is 10 and A, 1011 is 11 and B, 1100 is 12 and C, 1101 is 13 and D, 1110 is 14 and E, 1111 is 15 and F.

The picture shows all sixteen nibbles with their denary and hex values. You do not need to learn it by heart. Work any nibble out with the place values 8, 4, 2 and 1.

Binary to hexadecimal

Split the binary number into nibbles, starting from the right. Then write each nibble as one hex digit.

The 16 bits 1011010011110010 split into four nibbles 1011, 0100, 1111 and 0010, each in its own coloured box. Under each nibble its denary value is written, 11, 4, 15 and 2, and under that its hexadecimal digit, B, 4, F and 2. The result B4F2 is shown at the bottom.

Convert 1011010011110010 to hexadecimal.

  1. Nibbles: 1011 0100 1111 0010.
  2. Each nibble: 1011 is 11, which is B. 0100 is 4. 1111 is 15, which is F. 0010 is 2.
  3. Answer: B4F2.

If the number of bits is not a multiple of four, add 0s at the left. For example 110101 becomes 0011 0101, which is 35 in hex.

Hexadecimal to binary

Do the same thing backwards. Write each hex digit as four bits. Convert 7C: 7 is 0111 and C (12) is 1100, so 7C is 01111100.

Hexadecimal and denary

Hex to denary. Multiply each digit by its place value and add. For 7C: 7×16+12×1=112+12=1247 \times 16 + 12 \times 1 = 112 + 12 = 1247×16+12×1=112+12=124.

Denary to hex. Divide by 16. The whole-number part is the first digit and the remainder is the second digit. For 200: 200÷16=12200 \div 16 = 12200÷16=12 remainder 888. So 200 is C8 in hex. Check: 12×16+8=20012 \times 16 + 8 = 20012×16+8=200.

You can also go through binary. Convert 200 to binary (11001000), split it into nibbles (1100 1000) and write each as hex (C8).

For a four-digit hex number use the place values 4096, 256, 16 and 1. The largest 16-bit number, 65535, is FFFF.

Why we use hexadecimal

The computer itself still works in binary. Hexadecimal is for people. It is a shorter way to write binary, so it is easier to read, to remember and to type without mistakes. It is also quick to change back to binary, one digit at a time. A denary number does not split into bits so neatly.

Here are some places where you meet hexadecimal.

  • Colour codes in web pages. A colour such as FF8000 gives the amounts of red, green and blue, one byte each.
  • MAC addresses. The address of a network card is written as six bytes in hex, such as 00-1A-2B-3C-4D-5E.
  • Error codes. When a program crashes, the error code is often shown in hex.
  • Memory dumps. A programmer who looks at the contents of memory to find a fault sees them in hex.

Practise with new numbers

Try it in Python

The program converts a binary number to hex one nibble at a time, using a table of the sixteen digits. Then it checks the result with Python's own int(text, 16).

Read it first. Then run it. Which nibble gives the letter F?

1. Change the binary number to "1110001". It has seven bits. What does the program add at the left?

2. Change it to sixteen 1s. Predict the hex before you run it.

Common mistakes

  • Grouping from the left. Split binary into nibbles from the right, and pad the left nibble with 0s.
  • Reading hex as denary. Hex 25 is not twenty-five. It is 2×16+5=372 \times 16 + 5 = 372×16+5=37.
  • Forgetting the letters. A nibble of 1010 is A, not 10. One hex digit is always one character.
  • Thinking the computer stores hex. It stores binary. Hex is only a way for people to write it.

Remember these

  • Hexadecimal is base 16 and uses 0 to 9 and A to F.
  • One hex digit is one nibble (four bits). One byte is two hex digits.
  • Hex to binary: each digit becomes four bits. Binary to hex: group into nibbles from the right.
  • Hex is shorter than binary, so it is easier for people to read and less likely to be copied wrongly.

Check yourself

Try each one on your own first. If you are stuck, open a hint. Then check with Show the answer.

  1. Convert the hexadecimal number 3A to denary.
  1. Convert the binary number 11100110 to hexadecimal.
  1. Convert the hexadecimal number 9F to 8-bit binary.
  1. Convert the denary number 75 to hexadecimal.
  1. Give one reason why a programmer would rather read hexadecimal than binary.

Enroll free in Binary, Denary and Hexadecimal

Every lesson is open to read. Enrolling also lets you:

  • Mark lessons done and carry on where you stopped.
  • Take the tests of this lesson and its course.
  • Count the course towards the certificate for its chapter.
No payment. You can leave at any time.

Problems (3)

A web designer picks a green colour with the code 2E8B57…Easy · High School (9–10) · by StemPy Lab
A programmer is looking for a fault. One memory location holds the 16 bits 0110111110100011…Medium · High School (9–10) · by StemPy Lab
A network card has the address 00-1F-A7-3C-90-D2…Hard · High School (9–10) · by StemPy Lab
Next: lesson 3Binary addition, overflow, shifts and two's complement
← Binary, Denary and Hexadecimal
← Binary and denaryBinary addition, overflow, shifts and two's complement →

Discussion (0)

Log in to join the discussion.

Loading…

1 Python program
5 questions to check yourself

This lesson is free to read. Enroll free to keep your place and take the tests.