Computer ScienceExam code: 0984

Number Systems

Data Representation

This conversion is the fastest of the three pairings, because one hex digit always corresponds to exactly one nibble (4 bits).

Binary to hex

  1. Split the binary number into from the right, padding the leftmost group with zeros if needed.
  2. Convert each nibble to its denary value (0 to 15).
  3. Write each value as a single hex digit.

Hex to binary

  1. Take each hex digit and convert it to a 4-bit nibble.
  2. Join the nibbles together to form the full binary number.

Common exam question

Converting between binary and hexadecimal

Question: Convert an 8-bit or 16-bit binary number to hexadecimal, or write given hexadecimal numbers in binary (1–4 marks).

Asked in 6 of the 17 papers. Split the binary into nibbles from the right and turn each nibble into one hex digit. Most schemes give one mark per correct character in the correct order (two for an 8-bit number, four for a 16-bit one), though one paper gave a single mark for the whole answer. A nibble of 0000 is still a digit, so write the leading 0 (00001011 is 0B, and that 0 is one of the marks).

Going the other way, write every hex digit as a full four-bit nibble: the one paper that asked this set out its answers that way, so 2B becomes 0010 1011 and a three-digit hex number becomes twelve bits. Keep the nibbles in the same order as the digits.

Worked example

Converting binary to hexadecimal

Convert the binary number 11010110 to hexadecimal.

Solution:

  • Split into nibbles from the right: 1101 | 0110
  • Left nibble 1101: 8 + 4 + 1 = 13 → hex digit D
  • Right nibble 0110: 4 + 2 = 6 → hex digit 6
  • Result: D6

Quick check

3 short questions on this note. See what has stuck, and where to look if something hasn't.

About 1 minute

Build on this topic