OCR · GCSE · Computer Science

    Course version: J277 · Version from Sept 2022

    How to convert binary integers to their hexadecimal equivalents and vice…

    Full specification wording

    Data storage: How to convert binary integers to their hexadecimal equivalents and vice versa

    Hexadecimal is base 16, so each hex digit stands for a group of four binary bits (a nibble).

    Checked against the OCR J277 specification on .

    • Point 4 of 13
    • 4 key terms

    Study notes

    From the checked teaching notes for this specification point.

    The idea

    Hexadecimal is base 16, so each hex digit stands for a group of four binary bits (a nibble). To convert binary to hex, split the binary integer into nibbles from the right, pad the leftmost group with leading zeros if needed, then replace each nibble with its hex digit: 1010 becomes A, 1111 becomes F. For example 11011011 splits as 1101 1011, giving DB. To convert hex to binary, do the reverse: write each hex digit as its four-bit pattern and join them, so 2F becomes 0010 1111, or 101111 after dropping leading zeros. This works because 16 = 2⁴, so four binary place values map exactly onto one hex place value.

    What earns the marks

    • Splitting a binary integer into groups of four bits starting from the right-hand end, because each hex digit represents exactly four binary bits.
    • Padding the leftmost nibble with leading zeros when the binary integer does not contain a multiple of four bits, for example 10111 becomes 0001 0111.
    • Recalling the hex digit values 0-9 and A-F, where A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
    • Converting each nibble independently to its hex digit and joining the digits in the same left-to-right order as the nibbles.
    • Reversing the method for hex to binary by expanding every hex digit into a four-bit pattern and concatenating the patterns.
    • Removing leading zeros only after the full conversion, so that 0001 0111 is written as 10111 rather than with an incorrect internal gap such as 1 0111.

    Common mistakes and how to put them right

    • Grouping bits from the left instead of the right, which misaligns every nibble.

      Put it right by starting the grouping at the least significant bit.

    • Writing a hex digit as a decimal number, such as writing 12 instead of C.

      Put it right by learning the A-F values and using single hex characters.

    • Dropping leading zeros inside a nibble during hex-to-binary conversion, such as writing 111 for 7 instead of 0111.

      Put it right by writing four bits per hex digit before removing only the very first leading zeros.

    Exam tips

    • Show the nibble grouping explicitly, for example 1101 1011, so the examiner can follow your method even if a digit is wrong.
    • Check your answer by converting back: if DB is correct, then D = 1101 and B = 1011 should rebuild the original binary integer.
    • Keep place values in mind: the rightmost hex digit has value 16⁰, the next 16¹, then 16², which confirms why four bits are needed per digit.

    Try the lesson

    The start of the Data storage: How to convert binary integers to their hexadecimal equivalents and vice versa lesson, made from checked teaching notes for this specification point.

    Have a go first

    What is the hexadecimal equivalent of the binary integer 1101?

    Listen

    Hexadecimal is base 16, so each hex digit stands for a group of four binary bits (a nibble). To convert binary to hex, split the binary integer into nibbles from the right, pad the leftmost group with leading zeros if needed, then replace each nibble with its hex digit: 1010 becomes A, 1111 becomes F. For example 11011011 splits as 1101 1011, giving DB. To convert hex to binary, do the reverse: write each hex digit as its four-bit pattern and join them, so 2F becomes 0010 1111, or 101111 after dropping leading zeros. This works because 16 = 2⁴, so four binary place values map exactly onto one hex place value. A strong answer earns marks for these points. Splitting a binary integer into groups of four bits starting from the right-hand end, because each hex digit represents exactly four binary bits. Padding the leftmost nibble with leading zeros when the binary integer does not contain a multiple of four bits, for example 10111 becomes 0001 0111. Recalling the hex digit values 0-9 and A-F, where A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15. Converting each nibble independently to its hex digit and joining the digits in the same left-to-right order as the nibbles. A common slip: Grouping bits from the left instead of the right, which misaligns every nibble. Instead, starting the grouping at the least significant bit. Exam tip: Show the nibble grouping explicitly, for example 1101 1011, so the examiner can follow your method even if a digit is wrong.

    See it

    A top-down flowchart. It starts at a node labelled Binary integer, which leads to Split into nibbles from the right, then Pad leftmost nibble with leading zeros if needed, then Replace each nibble with its hex digit, then Join hex digits left to right, ending at Hexadecimal equivalent. From Hexadecimal equivalent the flow continues to Write each hex digit as its four-bit pattern, then Join the four-bit patterns, then Remove leading zeros only after full conversion, ending at Binary integer.
    Shows the steps for converting a binary integer to hexadecimal by grouping into nibbles, and the reverse steps for converting hexadecimal back to binary.

    Key words

    Say what each word means before you turn the card.

    Nibble

    Try answering aloud or in your head before turning the card.

    Hexadecimal

    Try answering aloud or in your head before turning the card.

    Leading zeros

    Try answering aloud or in your head before turning the card.

    Hex digit values

    Try answering aloud or in your head before turning the card.

    See every definition
    Nibble
    A group of four binary bits, which each hex digit stands for.
    Hexadecimal
    Base 16, where each digit represents a group of four binary bits.
    Leading zeros
    Zeros added to pad the leftmost nibble when the binary integer does not contain a multiple of four bits.
    Hex digit values
    The digits 0-9 and A-F, where A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.

    There is more to this lesson

    The full lesson goes on to check your understanding and help you earn the marks. Create a free account to carry on, with your progress saved.

    Carry on with the full lesson

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge

    Test your understanding of Data storage: How to convert binary integers to their hexadecimal equivalents and vice versa

    Active recall beats re-reading. Take an instant quiz now to test what you’ve learned and lock it into long-term memory.

    Take topic quiz

    A week of Premium from your first lesson · Then the free plan continues · No card, no charge