Skip to content

Hex to Binary Converter (Hex to Bits)

Convert hexadecimal to binary one digit at a time. For example, D1 becomes 11010001 because D maps to 1101 and 1 maps to 0001.

Runs in your browser Free, no sign-up
Loading tool workspace...

What is Hex to Binary Converter?

This hex to binary converter and calculator expands hexadecimal into the bits it represents. Each hex digit is exactly four bits, so the conversion is digit by digit: 3F is 0011 1111 and A7 is 1010 0111. Seeing the individual bits helps when you work with flags, masks, permission bits, color channels and protocol headers.

Paste hex values separated by spaces, such as FF 0A 3C, or one long value such as FF0A3C. Each value is shown in binary, padded with leading zeros to whole bytes so the bits line up (0A becomes 00001010), and you can choose how the output is separated.

How to use Hex to Binary Converter

  1. Enter hex values separated by spaces or commas, or one long hex value; 0x prefixes are fine.
  2. Read the binary result, padded to whole 8-bit bytes.
  3. Turn padding off or change the separator if you need a different layout.
  4. Copy the result, or click Swap to convert binary to hex.

Key features

  • Convert many values at once, separated by spaces or commas
  • Exact results for numbers of any size, including 64-bit values
  • Output separated by spaces, commas, new lines or nothing
  • Uppercase or lowercase hex, optional 0x prefix, and binary padded to whole 8-bit bytes
  • Swap button to reverse the conversion direction
  • Summary of a single value in binary, octal, decimal, hex and ASCII
  • Clear errors for invalid digits; runs entirely in your browser

Common use cases

  • Inspecting individual bits of flags, masks and registers
  • Reading hex dumps from Wireshark, xxd or debuggers as bits
  • Understanding color channel values in hex colors
  • Learning hexadecimal and binary for exams
  • Checking bit-level protocol and file-format fields

Technical details & standards

Each hex digit maps to four bits: 0 = 0000, 1 = 0001 … 9 = 1001, A = 1010, B = 1011, C = 1100, D = 1101, E = 1110 and F = 1111. Writing the groups side by side gives the binary number, so 2C becomes 0010 1100.

Values separated by spaces or commas are converted one by one, each as a whole number of any length, so FF0A3C becomes the 24 bits 111111110000101000111100. With byte padding on, every result is padded to a multiple of 8 bits; turn it off to drop leading zeros. Letters can be upper or lower case, and a minus sign gives a negative number.

How to convert hex to binary by hand

Going from hex to binary needs no arithmetic at all, only the 16-row table further down. Here is 2F9:

  1. Split the hex number into single digits: 2, F and 9.
  2. Replace each digit with its 4-bit group: 2 = 0010, F = 1111, 9 = 1001.
  3. Write the groups side by side in the same order: 0010 1111 1001.
  4. Drop leading zeros if you want the shortest form, or keep them to show whole nibbles.

Result: 2F9 in hex is 0010 1111 1001, or 1011111001 without the leading zeros. Going the other way, group bits in fours from the right and look each group up.

Hex to bin and hex to bytes in Python, JavaScript and xxd

Parse the hex as an integer, then format it in base 2. Pad to four bits per hex digit when each digit should keep its own group, and use bytes.fromhex when you need the raw bytes rather than a string of 0s and 1s.

JavaScript

parseInt("2F9", 16).toString(2);                 // "1011111001"
parseInt("90", 16).toString(2).padStart(8, "0"); // "10010000"
[..."3c"].map(d => parseInt(d, 16).toString(2).padStart(4, "0")).join(" "); // "0011 1100"

Python

h = "1F"
bin(int(h, 16))[2:].zfill(4 * len(h))   # '00011111', four bits per hex digit
f"{int('90', 16):08b}"                  # '10010000'

bytes.fromhex("48656c6c6f")             # b'Hello'
list(bytes.fromhex("ff00"))             # [255, 0]

Terminal (xxd)

echo 48656c6c6f | xxd -r -p > hello.bin   # hex to a binary file
xxd -b hello.bin
# 00000000: 01001000 01100101 01101100 01101100 01101111  Hello

xxd -r -p reads plain hex and writes the raw bytes; xxd -b prints any file as bits, eight per byte. xxd ships with Vim on macOS and Linux.

Hex to binary conversion table

Every hex digit is exactly four bits, so hex to binary is a lookup: replace each digit with its 4-bit group from the first table. For example, 3F is 0011 1111, and the largest digit, F, is 1111 with all four bits set. The second table lists byte values and bit masks that are often written in hex.

Hex digits 0–F in binary

HexBinaryDecimal
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115

Common hex values in binary

HexBinaryWhere you see it
0x0F0000 1111Mask for the low four bits (low nibble)
0xF01111 0000Mask for the high four bits (high nibble)
0x180001 1000Bits 3 and 4 set, the middle of the byte
0x400100 0000Only bit 6 set
0x550101 0101Alternating bits, a common test pattern
0xAA1010 1010Alternating bits, the inverse of 0x55
0x7F0111 1111Largest signed 8-bit value
0x801000 0000Sign bit of a signed byte
0x811000 0001Only the highest and lowest bits set
0x901001 0000Bits 7 and 4 set
0xFF1111 1111All 8 bits set
0x1000001 0000 0000256, one bit past a byte
0xFFFF1111 1111 1111 1111All 16 bits set

Frequently asked questions

How do I convert hex to binary?

Replace each hex digit with its 4-bit binary value. For B4: B is 1011 and 4 is 0100, so B4 is 10110100.

What is FF in binary?

11111111: F is 1111, so FF is eight ones, the largest value of a byte (255).

How many bits is one hex digit?

Four bits, also called a nibble. Two hex digits make one 8-bit byte.

How do I convert hex to binary in code?

JavaScript: parseInt("B4", 16).toString(2) gives "10110100". Python: bin(0xB4) gives '0b10110100', or format(0xB4, "08b") for an 8-bit string.

What is the hex to binary table?

0 = 0000, 1 = 0001, 2 = 0010, 3 = 0011, 4 = 0100, 5 = 0101, 6 = 0110, 7 = 0111, 8 = 1000, 9 = 1001, A = 1010, B = 1011, C = 1100, D = 1101, E = 1110 and F = 1111. Write a hex number's digits as these four-bit groups, in order, to get its binary form.

What is 0x90 in binary?

0x90 is 10010000 in binary: 9 = 1001 and 0 = 0000.

What is 0x40 in binary?

0x40 is 0100 0000: 4 = 0100 and 0 = 0000. Only bit 6 is set, so it equals 64 in decimal.

Can I convert a .hex file to a .bin file with this tool?

No. A firmware .hex file is usually in Intel HEX format: lines of records that carry addresses and checksums as well as data, so turning it into a .bin image means decoding those records, not converting digits. Use objcopy -I ihex -O binary firmware.hex firmware.bin for that. This tool converts hex numbers and byte strings into binary digits.

How do I convert a hex string to bytes in Python?

Use bytes.fromhex("48656c6c6f"), which returns b'Hello'; spaces between byte pairs are allowed, but a 0x prefix is not, so strip it first. The reverse is b"Hello".hex(). If you want the bits as text instead of bytes, use bin(int(h, 16))[2:].zfill(4 * len(h)).

More converters tools

View all