Hex to Binary Converter
To convert hex to binary, replace each hex digit with its four-bit group, called a nibble: 0 is 0000, 9 is 1001, A is 1010 and F is 1111. Write the groups in the same order. For example, 3C9 becomes 0011 1100 1001; drop the leading zeros if you want 1111001001.
Repeats forever:
Repeats forever:
Method: One hex digit, four bits
| Hex digit | Bits |
|---|---|
| 3 | 0011 |
| C | 1100 |
| 9 | 1001 |
Write the groups in order: 0011 1100 1001.
How to convert hex to binary by hand
No arithmetic is involved. Sixteen is two to the fourth, so each hex digit stands for exactly one pattern of four bits and the patterns never interact. You can translate a value of any length one character at a time, in any order, and still get the right answer.
- Take the hex digits one at a time, left to right.
- Look up each digit’s four-bit group in the nibble table.
- Write the groups side by side in the same order, keeping every inner zero.
- Optionally drop the zeros at the very front, unless you need a fixed width.
The one rule to respect is padding inside the number. The digit 3 is 0011, not 11: if you shorten an inner group, every bit to its left slides into the wrong place and the value changes.
Worked example: 3C9
Three digits become three nibbles, twelve bits
3C916 = 0011 1100 10012
| Hex digit | Bits |
|---|---|
| 3 | 0011 |
| C | 1100 |
| 9 | 1001 |
Write the groups in order: 0011 1100 1001.
The nibble table
A nibble is half a byte. These sixteen rows are the whole lookup; learn a few anchors and the rest follow. 8 is a lone high bit (1000), F is all four set, and A and 5 are the alternating patterns 1010 and 0101 that test engineers like because neighboring bits differ.
A digit and its complement to F are bit-for-bit opposites: 3 and C, 6 and 9, 1 and E. That pairing is handy when you are checking a mask and its inverse.
| Hex | Binary | Decimal |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Reading flag bytes
Status registers and option fields pack several yes-or-no switches into one byte, and documentation lists them as hex masks. Expanding the byte to bits shows which switches are on. The 6502 processor status register, laid out in MOS Technology’s MCS6500 programming manual, is a classic: a value of C3 is 1100 0011, so Negative, Overflow, Zero and Carry are set.
Each mask has a single 1 in it, so it is always 1, 2, 4 or 8 in one of the two digit positions. Testing a flag in code is status & 0x40, and the hex calculator can show that AND bit by bit.
| Bit | Mask | Bits | Flag |
|---|---|---|---|
| 0 | 01 | 0000 0001 | Carry |
| 1 | 02 | 0000 0010 | Zero |
| 2 | 04 | 0000 0100 | Interrupt disable |
| 3 | 08 | 0000 1000 | Decimal mode |
| 6 | 40 | 0100 0000 | Overflow |
| 7 | 80 | 1000 0000 | Negative |
When to keep the leading zeros
Mathematically, 0011 1100 1001 and 1111001001 are the same number. Which one to write depends on what the bits mean. A register, a byte in a packet or a pixel channel has a fixed size, and the high zeros are real bits that happen to be off; dropping them hides the size. A plain quantity has no width, and the short form is cleaner.
The converter always groups binary in nibbles and keeps the zeros needed to complete the leftmost group only when a bit width is chosen on the home converter. Here the result keeps its natural length.
Questions people ask
Why does each hex digit equal four binary digits?
Because 16 = 2⁴. Four bits have exactly 16 combinations, 0000 to 1111, one for each hex digit from 0 to F, so every hex digit maps to one fixed group of four bits.
What is FF in binary?
11111111. Each F is 1111, so FF is two full nibbles, eight ones in a row, which is 255 in decimal.
Should I keep leading zeros when converting hex to binary?
Inside the number, yes: 3C9 must be written 0011 1100 1001 so each digit keeps its four bits. Only the zeros at the very front can be dropped, giving 1111001001; keep them when you need a fixed width such as a full byte.
What is 0xA in binary?
1010. A is 10 in decimal, which is 8 + 2, so the bits worth 8 and 2 are set.
Related conversions
Last updated