Developer Bases

Binary to hex

Binary value
Hexadecimal AF
Group into fours from the right
The same number elsewhere
Decimal 175
Binary 10101111
Binary, grouped 1010 1111
Octal 257
Bits needed 8
Note
Pad on the left, never the right
DecimalBinaryOctalHex
0000
1111
81000108
10101012A
15111117F
16100002010
64100000010040
100110010014464
25511111111377FF
256100000000400100
1024100000000002000400
655351111111111111111177777FFFF
Advertisement
320 × 100

Group the binary digits into fours starting from the right, padding the left with zeros, then read each group as one hex digit. 10101111 becomes 1010 1111, which is AF.

How to convert binary to hex

1 Enter the bits. Spaces, underscores and commas between groups are accepted and ignored.
2 Read the hexadecimal result, with the grouped binary showing where the nibbles fell.
3 Pad from the left, never the right, or every digit shifts.
4 Use the decimal row as a sanity check on a long string.

Padding direction is the mistake worth avoiding. Binary places carry value by position from the right, so a group of fewer than four bits must be padded on the left with zeros. The grouped output above always pads correctly, which is why it is worth reading rather than doing it by eye on a long string.

Six bits make the point concretely. 110110 padded on the left is 0011 0110, which reads as 36 in hex and 54 in decimal. Padded on the right it would be 1101 1000 — D8, or 216 — four times too large, because every bit has been shoved two places up. Grouping always starts from the right for exactly this reason.

Two things this will not do. It reads the whole input as one number, separators and all, so it will not treat each group as a separate byte; if your bits are one character per group, binary to ASCII is the tool. And leading zeros are not printed, so 0011 0110 comes back as 36 rather than 036; zeros on the left carry width, not value, so pad the hex yourself where a fixed number of digits matters.

Questions

F, which is 15 in decimal.

Advertisement
300 × 250
Was this tool any good?
Internal signal only · I use it to find the tools worth rebuilding