Study Guide

Hexadecimal

Why people write binary in groups of four bits as base 16, how to convert between hexadecimal, binary and denary, and where hexadecimal is used.

Lesson 1.2 Data Representation

For: Cambridge IGCSE Computer Science learners, or anyone who can already convert between binary and denary

Stage: Think

A code that is hard to read

Mia belongs to her school’s robotics club. When her robot goes wrong, its controller shows an error code as sixteen bits, and she has to read it out so that a friend can look it up in the manual. Today the screen shows this: 1011010011100001. (Mia, the club and the robot are fictional.)

Think it through

What could go wrong when Mia reads sixteen 1s and 0s aloud, and what could she do to make the code easier to say and to copy?

Show what happens

It is easy to skip a digit, repeat one or lose the place, because every digit looks like the one before it. Splitting the code into short groups, such as 1011 0100 1110 0001, helps. The next step shows a way of splitting it that also makes it much shorter.

Stage: Discover

Four bits at a time

Mia splits her code into groups of four bits: 1011 0100 1110 0001. Look at just one group.

Think it through

How many different patterns can a group of four bits make? What are the smallest and the largest values it can hold, in denary?

Show what happens

Four bits make 2 × 2 × 2 × 2 = 16 patterns, the values 0 to 15 (0000 to 1111, which is 8 + 4 + 2 + 1 = 15).

A group of four bits is called a nibble, because it is half a byte. If every nibble is to be written as a single symbol, there must be sixteen different symbols. Denary has only ten digits, 0 to 9, so the extra six are borrowed from the alphabet: A is ten, B is eleven, C is twelve, D is thirteen, E is fourteen and F is fifteen.

Writing numbers with these sixteen symbols, where each column is worth sixteen times the column to its right, is called hexadecimal, “hex” for short, or base 16.

DenaryBinaryHexadecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
101010A
111011B
121100C
131101D
141110E
151111F

You do not need to memorise this table. Any row can be rebuilt from the place values 8, 4, 2 and 1: for 1101 add 8 + 4 + 1 = 13, and 13 is D.

Check your understanding

Which hexadecimal digit stands for the nibble 1101?
Show the answer

Answer: B. D, because 8 + 4 + 1 = 13, and D is thirteen.

1101 is 8 + 4 + 1 = 13, and the symbol for thirteen is D.

Stage: Explain

From binary to hexadecimal

Now Mia’s whole code, 1011 0100 1110 0001, can be written with one symbol for each nibble.

Think it through

Use the table to find the symbol for each of Mia’s four nibbles, and write her code in hexadecimal.

Show a model answer

1011 is 11, which is B. 0100 is 4. 1110 is 14, which is E. 0001 is 1. The code is B4E1: four symbols instead of sixteen digits.

  1. Split the binary number into nibbles. It is already split: 1001, 1100 and 0111.
  2. Work out each nibble’s value. 1001 is 8 + 1 = 9. 1100 is 8 + 4 = 12. 0111 is 4 + 2 + 1 = 7.
  3. Write each value as one hexadecimal symbol. 9 is 9, 12 is C and 7 is 7.
  4. Join the symbols in the same order. The answer is 9C7.
  5. Check by converting back. 9C7 is 9 × 256 + 12 × 16 + 7 = 2304 + 192 + 7 = 2503, and 100111000111 in binary is 2048 + 256 + 128 + 64 + 4 + 2 + 1 = 2503. The two agree.

Each nibble is converted on its own, because four bits is exactly one hexadecimal digit. There is no carrying from one nibble to the next.

First try some with the first row worked for you.

Binary to hexadecimal, one nibble at a time
BinaryHexadecimal
0011 11103E
1001 0101
1100 1111
0000 1011 1000 0001
1111 1111 1111 1111

    Show the completed table
    BinaryHexadecimal
    0011 11103E
    1001 010195
    1100 1111CF
    0000 1011 1000 00010B81
    1111 1111 1111 1111FFFF

    Stage: Discover

    When the bits do not split into fours

    Think it through

    The binary number 101101 has six bits, but nibbles need four. Should you start making groups of four from the left or from the right? What do you do about the bits left over?

    Show what happens

    Start from the right. Zeros can be added to the front of a number without changing it, just as 0325 is still 325. So 101101 splits as 10 | 1101, and the short group is filled out to 0010. Then 0010 is 2 and 1101 is D, so the number is 2D.

    Check your understanding

    What is the binary number 1101101 in hexadecimal?
    Show the answer

    Answer: C. 6D, from the groups 0110 and 1101, starting from the right.

    Group from the right: 110 | 1101. Fill the short group out to 0110. 0110 is 6 and 1101 is D, so 1101101 is 6D.

    Stage: Predict

    From hexadecimal back to binary

    Mia’s friend finds a code in the manual: 2F9C. To compare it with the robot’s memory, she needs it in binary.

    Think it through

    Using what you know about nibbles, how could you turn 2F9C back into binary? Write down your plan and then try it.

    Show a model answer

    Turn each symbol into its own nibble, in the same order: 2 is 0010, F is 1111, 9 is 1001 and C is 1100. So 2F9C is 0010 1111 1001 1100. Each symbol always gives exactly four bits, so a leading nibble may start with 0s, as 0010 does.

    Now try it for yourself, with the first row worked.

    Hexadecimal to binary, one symbol at a time
    HexadecimalBinary
    A51010 0101
    2F
    C3
    90
    1B7C

      Show the completed table
      HexadecimalBinary
      A51010 0101
      2F0010 1111
      C31100 0011
      901001 0000
      1B7C0001 1011 0111 1100

      Stage: Discover

      Hexadecimal and denary

      So far hexadecimal has gone through binary. It can also be converted to denary directly, by thinking about its columns.

      Think it through

      In denary the columns from the right are worth 1, 10 and 100: each is ten times the one before. In binary they are 1, 2, 4 and 8: each is twice the one before. What would you expect the first four columns of a base 16 number to be worth?

      Show what happens

      1, 16, 256 and 4096: 1 × 16 = 16, 16 × 16 = 256 and 256 × 16 = 4096.

      Hexadecimal to denary: 1A7.

      1. Write the column values above the digits: 256, 16 and 1.
      2. Turn each symbol into its value. 1 is 1, A is ten and 7 is 7.
      3. Multiply each value by its column and add. 1 × 256 + 10 × 16 + 7 × 1 = 256 + 160 + 7 = 423.

      Denary to hexadecimal: 183.

      1. Divide by 16 and keep the remainder. 183 ÷ 16 = 11 remainder 7. The remainder 7 is the right-hand digit, because it is the part that is not a whole sixteen.
      2. Divide the answer again. 11 ÷ 16 = 0 remainder 11. Eleven is B, the next digit to the left. The answer has reached 0, so stop.
      3. Read the remainders from last to first. B then 7, so 183 is B7.
      4. Check. B7 is 11 × 16 + 7 = 176 + 7 = 183.

      A second route gives the same answer: 183 is 10110111 in binary, which is 1011 0111, which is B7.

      A 16-bit number has columns worth 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384 and 32768. Splitting it into four nibbles and converting through hexadecimal is often quicker than adding up sixteen columns.

      Converting directly works too, exactly as for 8 bits: add the values of the columns that hold a 1, or, from denary, take away the largest column value that fits and carry on with what is left.

      16-bit binary and denary, converted directly
      16-bit binaryDenary
      0000 0001 0000 0001
      0010 0000 0000 0000
      1000 0000 0000 0001
      1000
      40000

        Show the completed table
        16-bit binaryDenary
        0000 0001 0000 0001257
        0010 0000 0000 00008192
        1000 0000 0000 000132769
        0000 0011 1110 10001000
        1001 1100 0100 000040000

        Do not confuse: The same symbols, three different numbers

        In denary10
        ten1 × 10 + 0 × 1
        In binary10
        two1 × 2 + 0 × 1
        In hexadecimal10
        sixteen1 × 16 + 0 × 1

        To avoid confusion, a small number can show the base: 10₂ is binary, 10₁₆ is hexadecimal. Some programming languages write a hexadecimal number with 0x in front, and web colours use a # sign.

        Three ways to write the same number
        BinaryHexadecimalDenary
        0010 11112F47
        1100 1000
        5A
        255
        B7
        0001 0000 0000 0000

          Show the completed table
          BinaryHexadecimalDenary
          0010 11112F47
          1100 1000C8200
          0101 10105A90
          1111 1111FF255
          1011 0111B7183
          0001 0000 0000 000010004096

          Check your understanding

          What is the hexadecimal number 7C in denary?
          Show the answer

          Answer: A. 124, from 7 × 16 + 12 × 1.

          7 × 16 = 112, and C is twelve, so 7C = 112 + 12 = 124.

          Stage: Explain

          Why people use hexadecimal

          Think it through

          A 16-bit value could be written in binary (sixteen digits), in denary (up to five digits) or in hexadecimal (four digits). Which would you choose for people who must read it out, copy it and remember it? Which one lets you find the underlying bits most easily? Explain your choices.

          Show a model answer

          Hexadecimal is much shorter than binary, which makes it easier to read, say, write down and remember, and means fewer mistakes. It also lines up exactly with the bits: every symbol is one nibble, so the binary can be written straight from it. Denary is short, but its columns do not line up with bits, so converting means arithmetic. For example 4F2A is 0100 1111 0010 1010 at once, but nothing in 20,266 shows the bits.

          Hexadecimal is used because it is easier for people than long binary. It is not used because computers prefer it. It is shorter, so it is easier to read, write and remember, it leads to fewer errors, and it converts to and from binary exactly, one symbol per nibble.

          Where it appears, with invented examples:

          Where it is usedWhat it looks likeWhy hexadecimal helps
          MAC addresses (the 48-bit address of a network device)3C:5A:B4:1F:90:7EForty-eight bits would be 48 digits. In hexadecimal it is 12 symbols, written as 6 pairs, one pair per byte.
          Error messages and error codesError 0x00A3A short code is easy to type into a search or quote to a helpdesk.
          HTML colour codes#FF8000Three pairs give the red, green and blue amounts, each from 00 to FF (0 to 255). Here FF is 255, 80 is 128 and 00 is 0: orange.
          Memory dumps (a printout of what is stored in memory)3C 7F 00 A9Each byte is exactly two symbols, so the printout stays neat and each byte can be read quickly.
          IPv6 addresses (128-bit internet addresses)2001:0DB8:85A3:0000:0000:8A2E:0370:7334A 128-bit address is eight groups of four symbols. In binary it would be 128 digits.

          Hexadecimal is only a way of writing bits for people. Inside the computer the value is still stored as bits: 4F2A takes exactly the same memory as 0100 1111 0010 1010. It is not encrypted, not compressed, and not stored differently.

          Check your understanding

          A programmer writes a memory address as 4F2A instead of 0100111100101010. Why?
          Show the answer

          Answer: C. It is shorter for people to read and copy, and each symbol is exactly four bits.

          Hexadecimal is for people. Four symbols are easier to read, copy and remember than sixteen digits, and each symbol converts to exactly four bits.

          Stage: Apply

          Use it somewhere new

          A school’s web page uses the background colour code #00A0FF. The three pairs of symbols are the amounts of red (00), green (A0) and blue (FF), each from 0 to 255.

          Apply it

          What is the amount of green, A0, in denary?
          Show the answer

          Answer: B. 160, because A is in the sixteens column: 10 × 16 + 0.

          A0 = 10 × 16 + 0 × 1 = 160.

          A fictional rain gauge sends its reading as a 16-bit pattern: 0000 0011 1110 1000.

          Apply it

          What is the reading in denary?
          Show the answer

          Answer: D. 1000, because the pattern is 03E8: 3 × 256 + 14 × 16 + 8.

          The nibbles are 0000 (0), 0011 (3), 1110 (E) and 1000 (8), so the pattern is 03E8. Then 3 × 256 + 14 × 16 + 8 × 1 = 768 + 224 + 8 = 1000.

          Apply it

          Leo converts 1010 1111 to hexadecimal and writes FA. What has Leo done?
          Show the answer

          Answer: A. He wrote the nibbles in the wrong order: 1010 is A and 1111 is F, so it is AF.

          1010 is A and 1111 is F, so the answer is AF. Leo’s FA is a different number: 15 × 16 + 10 = 250 instead of 10 × 16 + 15 = 175.

          Stage: Consolidate

          Bring it together

          Think it through

          Without looking back, explain to a friend how you would convert the hexadecimal number 3C to binary and to denary, and why hexadecimal is used at all.

          Show a model answer

          For binary, turn each symbol into a nibble: 3 is 0011 and C (twelve) is 1100, so 3C is 0011 1100. For denary, use the columns 16 and 1: 3 × 16 + 12 = 60. Hexadecimal is used because it is a shorter, more readable way for people to write binary, with fewer mistakes, and it converts to bits exactly, one symbol per nibble.

          Check your understanding

          What is the largest value that four hexadecimal digits can hold?
          Show the answer

          Answer: B. 65,535, because FFFF has every one of the sixteen bits set to 1.

          FFFF is 15 × 4096 + 15 × 256 + 15 × 16 + 15 = 61,440 + 3,840 + 240 + 15 = 65,535, the same as 16 bits all on.

          • A group of four bits is a nibble. It has 16 patterns, so it can be written as one hexadecimal (base 16) digit: 0 to 9, then A to F for ten to fifteen.
          • To convert binary to hexadecimal, split into nibbles starting at the right, filling the first with leading zeros if needed, and write one symbol for each. To go back, write four bits for each symbol.
          • To convert hexadecimal to denary, multiply each symbol’s value by its column: 1, 16, 256, 4096. To go from denary to hexadecimal, divide by 16 repeatedly and read the remainders from last to first, or go through binary.
          • Hexadecimal 10 is sixteen, not ten.
          • Hexadecimal is used because it is easier for people to read, write and remember than binary, with fewer errors, for example in MAC addresses, error messages, HTML colour codes, memory dumps and IPv6 addresses. Inside the computer the data is still bits.

          Sources and scope

          • What this lesson is. The second lesson of the Data Representation module, written for this site. It teaches the hexadecimal part of Cambridge IGCSE Computer Science 1.1, points 2 and 3, with the same sections of the 2026 to 2028 syllabus (version 6) used for its curriculum links. Those links are provisional: no link has been verified by the site owner, and they show where the lesson may help with a course. They imply no review or endorsement by any examination board.
          • Original material. Mia, her robotics club and her robot, the rain gauge, the school web page and its colour code, the MAC address, the error code and the memory-dump line are fictional examples written for this lesson. The IPv6 address is a documentation example reserved for use in books and guides.
          • Simplified on purpose. Conversion is for positive whole numbers only, up to 16 bits and four hexadecimal digits. Negative numbers are in the lesson on two’s complement. Real error codes and memory dumps are longer and use more conventions than the short invented ones shown here.