Skip to content
BetterDL

Binary–hex conversion

Also called: binary to hex, hex to binary, binary to hexadecimal, hexadecimal to binary

Converting between binary and hexadecimal by swapping each 4-bit group (nibble) for one hex digit, grouping from the right.

Since 16 = 2⁴, every hexadecimal digit stands for exactly four bits. That makes conversion between binary and hex a pure lookup, with no arithmetic.

Binary → hex:

  1. Split the bits into groups of 4, starting from the right (the LSB).
  2. If the leftmost group is short, pad it with zeros on its left.
  3. Replace each group with its hex digit, from 0000 = 0 to 1111 = F.

Hex → binary: replace each digit with its 4-bit nibble, keeping all four bits (3 is 0011, not 11). You may drop leading zeros of the whole number afterwards.

Why from the right? Each hex digit covers a fixed set of weights: the rightmost covers 8, 4, 2, 1, the next covers 128, 64, 32, 16, and so on. Grouping from the left misaligns every group, and padding on the right adds zeros to the end of the number, doubling it each time.

Because it's so easy, hex is the normal way for people to write binary. Octal works the same way with 3-bit groups (binary octal conversion).

1
64
0
32
1
16
1
8
1
4
0
2
1
1

Worked examples

Example

1011101₂ to hex

Group from the right, then compare with the wrong way.

  1. 1.

    From the right: 101 | 1101. Pad the short group: 0101 | 1101.

  2. 2.

    0101 = 5 and 1101 = D, so the answer is 5D₁₆.

  3. 3.

    Check: 64 + 16 + 8 + 4 + 1 = 93, and 5 × 16 + 13 = 93.

  4. 4.

    Wrong way: grouping from the left gives 1011 | 101, padded on the right to 1011 | 1010 = BA₁₆ = 186. That's double the real value.

Example

3A₁₆ to binary

3 → 0011, A → 1010. Together 00111010, or 111010₂ without the leading zeros. Check: 32 + 16 + 8 + 2 = 58 = 3 × 16 + 10.

Common mistakes

  • Grouping from the left.

  • Writing a digit with fewer than 4 bits in the middle of a number: 2 must be 0010.

  • Treating A–F as two-digit numbers instead of one nibble each.

Practice Binary–hex conversion

Interactive questions with instant feedback and a worked solution for every wrong answer.

Learn it step by step

Binary–hex conversion is taught in Number Systems.