↑ ↓ to moveEnter to openEsc to close

Binary to hex converter

Paste a string of ones and zeros and see it split into four-bit groups, each replaced by one hex digit. Spaces and underscores are ignored.

  • Hex
  • Decimal

Grouped from the right

Group from the right, then look up

Converting binary to hex has two steps:

  1. Split the bits into groups of four, starting from the right-hand end. If the leftmost group is short, pad it with zeros on the left.
  2. Replace each group with its hex digit: 0000 is 0, 1001 is 9, 1010 is A, 1111 is F.

Starting from the right matters. Grouping from the left gives a different, wrong answer whenever the length isn't a multiple of four.

Example: 10110110111001

That's 14 bits. Two zeros are added on the left to make 16:

GroupPlace valuesSumHex
0010222
11018 + 4 + 113D
10118 + 2 + 111B
10018 + 199

Result: 0x2DB9, or 11,705 in decimal. The steps panel draws the same table for whatever you paste, padding included.

If you had grouped from the left (1011 0110 1110 01), the last group would be "01" and you would get B6E1, which is a different number entirely.

Quick reference

BinaryHexBinaryHex
0000010008
001131010A
010151100C
011171111F

Two patterns are worth knowing by sight: 1010 is A and 0101 is 5. Alternating bit patterns such as 0xAA and 0x55 are used constantly as test values in memory and serial communication, because they toggle every bit.

Input rules

  • Spaces, line breaks and underscores are ignored, so you can paste bits grouped any way you like.
  • A 0b prefix is accepted.
  • Anything other than 0 and 1 is reported by name. The tool doesn't drop it silently, because a stray 2 or letter O usually means you've copied the wrong thing.

Output options

  • 0x prefix adds the usual code notation.
  • Space between bytes splits the hex into pairs (2D B9), which matches how hex editors and packet dumps display data. An odd number of digits gets a leading zero first, so the pairs stay aligned to bytes.

The decimal value is shown too, with exact BigInt math, so a 128-bit string converts without rounding.

Where binary strings come from

  • Bit fields in datasheets: a register diagram gives you individual bits, and you need the hex value to write in code.
  • Logic analyzer and serial captures, which often show raw bits.
  • Networking: subnet masks in binary, such as 11111111 11111111 11110000 00000000, become FF FF F0 00, which is 255.255.240.0 or /20.
  • Homework and exams, where showing the grouping step is the point.

Checking your work

Converting back is the fastest check. Paste the hex result into hex to binary and you should get your original bits, plus any leading zeros that padding added. Leading zeros don't change the value.

Doing it in code

Most languages convert in one line. The first three rows print 2DB9 for the example above:

LanguageCode
JavaScriptparseInt('10110110111001', 2).toString(16).toUpperCase()
Pythonformat(int('10110110111001', 2), 'X')
C (GCC/Clang)printf("%X", 0b10110110111001);
Excel / Sheets=BIN2HEX("10110110111001")

Two caveats. JavaScript's parseInt loses precision past 53 bits, so use BigInt('0b' + bits).toString(16) for long strings. And Excel's BIN2HEX accepts at most 10 bits, treating a leading 1 in a 10-bit string as negative, which is why it refuses this 14-bit example.

For the decimal value with the place-value method, use hex to decimal on the result. To go straight from decimal, use decimal to hex. For bitwise operations, open the hex calculator.

FAQ

What if my binary has a fractional part?

This tool converts whole numbers only. For fractions, group the bits after the point in fours from the left (the opposite direction), padding on the right.

Why group by four and not eight?

Each hex digit covers four bits. Grouping by eight gives you bytes, which are two hex digits each, so it works too, but you still read the result four bits at a time.

Is 1111 1111 equal to 255 or −1?

Both, depending on how it's read. Unsigned it's 255 (0xFF). As an 8-bit signed value in two's complement it's −1. The hex to decimal page can show either reading.