Binary to Hex Converter
To convert binary to hex, split the bits into groups of four starting from the right, pad the leftmost group with zeros, and replace each group with one hex digit. For example, 101101101 groups as 0001 0110 1101, which reads 1, 6 and D, so the result is 16D.
Repeats forever:
Repeats forever:
Method: Group bits by four from the right
| Group | Hex digit |
|---|---|
| 0001 | 1 |
| 0110 | 6 |
| 1101 | D |
Result: 16D.
How to convert binary to hex by hand
Long runs of ones and zeros are hard to read and easy to miscopy. Cutting them into fours turns them into hex, which is the shorthand people actually use for bit patterns; every group of four maps to exactly one digit.
- Start at the rightmost bit, the ones place.
- Mark off groups of four bits moving left.
- Pad the last, leftmost group with zeros until it also has four bits.
- Replace each group with its hex digit, 0000 = 0 through 1111 = F.
- Write the digits in the same left-to-right order.
Paste binary with or without spaces, underscores or a 0b prefix; the converter ignores the formatting and regroups the bits itself. A trailing b, as in some assembly syntaxes, is read as a binary marker too.
Worked example: 1 0110 1101
Nine bits: two full groups and a single leftover bit
1011011012 = 16D16
| Group | Hex digit |
|---|---|
| 0001 | 1 |
| 0110 | 6 |
| 1101 | D |
Result: 16D.
The grouping mistake that gives a wrong answer
Grouping from the left feels natural because that is how we read, and when the bit count is a multiple of four it even works. With nine bits it does not. Starting at the left gives 1011 0110 1; padding that stray bit on the right turns it into 1000, and you get B68, which is 2920 instead of 365.
The ones place is always the rightmost bit, so that is where the first group must end. Pad on the left, where extra zeros cost nothing.
| Grouping | Groups | Hex | Decimal |
|---|---|---|---|
| From the right | 0001 0110 1101 | 16D | 365 |
| From the left (wrong) | 1011 0110 1000 | B68 | 2920 |
Binary fractions
After the point the direction reverses. Bits to the right of the point are grouped starting at the point and moving right, and the last group is padded with zeros on its right. In 101.1 the whole part pads to 0101 and the fraction to 1000, giving 5.8.
Both readings agree in decimal: one half is 0.5, and 8 sixteenths is also 0.5, so the value is 5.5 either way. A fraction with a finite number of bits always ends in hex, because every group of four bits is one exact hex digit.
101.12 = 5.816 = 5.510
| Group | Hex digit |
|---|---|
| 0101 | 5 |
| . | . |
| 1000 | 8 |
Result: 5.8.
Questions people ask
Why do you group binary digits from the right?
The groups have to line up with the ones place. Grouping 101101101 from the right gives 1 0110 1101 = 16D. Grouping from the left gives 1011 0110 1, and the last single bit no longer sits in the ones place, so the answer comes out wrong.
What if the number of bits is not a multiple of four?
Add zeros on the left until it is. Leading zeros do not change the value, so 101 becomes 0101, which is the hex digit 5.
What is 11111111 in hex?
FF. The two groups 1111 and 1111 are both F. It is 255 in decimal, the largest value that fits in one byte.
How do you convert a binary fraction to hex?
Group the bits after the point in fours from the left and pad with zeros on the right. 101.1 becomes 0101.1000, which is 5.8 in hex, or 5.5 in decimal.
Related conversions
Last updated