Binary to Hex

Four bits become one hex digit — grouped from the right, padded on the left, which is the half of this conversion people get backwards.

Runs 100% in your browserNothing is uploaded to a serverFree forever

Binary

Hexadecimal

Copied!

Group in fours, from the right

Because sixteen is two to the fourth, every four bits become exactly one hex digit. The only thing to be careful about is the direction: you group from the right, because the rightmost bit is the ones column and place value is what has to stay aligned. Group from the left and every digit after the first is wrong.

If the string does not divide by four, pad the left with zeros until it does. Padding on the left never changes the value; padding on the right multiplies it by two each time.

Grouping from the right, with the padding made explicit
Binary as typedPadded and groupedHexDecimal
1000111
101010155
110100001 10101A26
1101001110001 1010 01111A7423
11110000111100001111 0000 1111 0000F0F061680
100000000000000000000000000000001000 0000 0000 0000 0000 0000 0000 0000800000002147483648

Look at the second row. 101 is five, and the padded form 0101 is still five. Had the pad gone on the other end, 1010, you would have ten — the exact error this convention exists to prevent.

Hex is how you read long binary

A 32-bit value written in binary is thirty-two characters that all look the same, and counting to bit 19 in that string by eye is a mistake waiting to happen. The same value in hex is eight characters, each standing for a known group of four, so bit 19 is "the second bit of the fifth digit from the right" and you can find it without counting to nineteen.

That is why hex, not decimal, is the notation used for register dumps, hash digests, memory addresses and packet captures: it compresses binary by a factor of four while keeping the bit boundaries visible.

Widths, and reading the sign

Set a width above and the hex is padded to the full field — two digits for a byte, four for a 16-bit word, eight for a 32-bit word, sixteen for 64. Tick signed as well and you also get told what that pattern means as a two's-complement number, which is the answer you want when the binary came out of a debugger showing an int.

Spaces and underscores in the input are ignored, so binary pasted out of a datasheet in nibble groups converts as-is.

Related: hex to binary for the return trip, binary to decimal for a magnitude, and the full converter for every base at once.

More developer tools