Hex to binary converter
One hex digit is exactly four bits, so converting is a lookup rather than arithmetic. Type hex to see each digit become its nibble, or binary to see it grouped back into hex. Octal works the same way in groups of three.
Working: each hex digit becomes 4 bits
The nibble table
This is the whole method. Each hex digit maps to one four bit pattern and back, and the patterns are just the numbers 0 to 15 written in binary.
| Hex | Binary | Decimal | Hex | Binary | Decimal |
|---|---|---|---|---|---|
| 0 | 0000 | 0 | 8 | 1000 | 8 |
| 1 | 0001 | 1 | 9 | 1001 | 9 |
| 2 | 0010 | 2 | A | 1010 | 10 |
| 3 | 0011 | 3 | B | 1011 | 11 |
| 4 | 0100 | 4 | C | 1100 | 12 |
| 5 | 0101 | 5 | D | 1101 | 13 |
| 6 | 0110 | 6 | E | 1110 | 14 |
| 7 | 0111 | 7 | F | 1111 | 15 |
The bits in a nibble are worth 8, 4, 2 and 1. So C = 12 = 8 + 4 is 1100, and 9 = 8 + 1 is 1001.
Why grouping works, and why from the right
In binary each place is worth twice the one to its right. Four places together cover 24 = 16 values, so every block of four bits is one base 16 digit, and each block's place value is the next power of 16. The blocks never interfere with each other, which is why one digit can be converted without looking at the rest.
Hex B7 to binary
B → 1011
7 → 0111
B7 = 1011 0111
Binary 1101011 to hex
Pad to 8 bits: 0110 1011
0110 → 6
1011 → B
1101011 = 6B
The groups start from the right because that is where the place values start: the rightmost bit is always worth 1. Group 1101011 from the left and you get 1101 and 011, which read as D3, not 6B. The hex to decimal converter shows how the digits turn into a value, and the binary calculator does arithmetic on the bits themselves.
Octal and binary: groups of three
Octal is base 8, and 8 is 23, so each octal digit is exactly three bits. It is rarer than hex today, but Unix file permissions still use it, because the permission bits come in threes.
| Octal | Binary |
|---|---|
| 0 | 000 |
| 1 | 001 |
| 2 | 010 |
| 3 | 011 |
| 4 | 100 |
| 5 | 101 |
| 6 | 110 |
| 7 | 111 |
chmod 755
7 → 111 → rwx (owner)
5 → 101 → r-x (group)
5 → 101 → r-x (others)
Each group of three bits is read, write and execute. 755 gives the owner everything and everyone else read and execute. Convert it
Questions
How do I convert hex to binary?
Replace each hex digit with its four bit pattern from the table and write the groups side by side. B7 is B = 1011 and 7 = 0111, so B7 is 1011 0111. Leading zeros of the first group can be dropped. No arithmetic is needed, because one hex digit is exactly four bits.
How do I convert binary to hex?
Split the bits into groups of four starting from the right, pad the leftmost group with zeros if it is short, and replace each group with its hex digit. 1101011 becomes 0110 1011, which is 6B. Starting from the left would give the wrong answer whenever the length is not a multiple of four.
What is a nibble?
Four bits, half a byte. It holds 16 values, 0000 to 1111, which is exactly one hex digit, so a byte is always written as two hex digits: the high nibble and the low nibble.
How do I convert octal to binary?
The same way as hex, with groups of three: each octal digit 0 to 7 becomes three bits. 755 is 111 101 101. Going back, split the bits into threes from the right.
Why can I not do the same with decimal?
Because 10 is not a power of 2. A decimal digit needs between three and four bits and the digits do not line up with bit boundaries, so converting decimal to binary needs real division, as the binary converter and the hex to decimal page show. Binary coded decimal sidesteps this by storing each decimal digit in its own four bits, at the cost of wasting six of the sixteen patterns.
How long a number can this convert?
Up to 64 digits of whatever base you type, so 64 hex digits (256 bits) or 64 bits of binary. Spaces and underscores are ignored, as are a leading 0x, 0b or 0o.