Skip to content
AgileLogics

Hexadecimal to Binary

Converts a base-16 (hexadecimal) number into its base-2 (binary) equivalent.

How it works

Enter a hex number (e.g. ff) and click Convert.

How do you convert hex to binary?

Swap every hexadecimal digit for the four binary digits it represents, then write them side by side. Since 16 is 2 to the power 4, one hex digit always corresponds to exactly four bits, so the conversion is a lookup rather than a calculation. A5 becomes 1010 followed by 0101, giving 10100101.

People usually go this direction to see which individual bits are switched on: flags in a protocol header, a hardware register, a bitmask in a config file.

How to use it

  1. Enter the hex value, such as CAFE or cafe.
  2. Click Convert.
  3. Read the bits: 1100101011111110.

Expansion table

Each digit, its bits, and which of the four place values (8, 4, 2, 1) are set:

Hex Bits Places set
0 0000 none
1 0001 1
2 0010 2
3 0011 2+1
4 0100 4
5 0101 4+1
6 0110 4+2
7 0111 4+2+1
8 1000 8
9 1001 8+1
a 1010 8+2
b 1011 8+2+1
c 1100 8+4
d 1101 8+4+1
e 1110 8+4+2
f 1111 8+4+2+1

The padding gotcha

The converter treats your input as a number, and numbers don't keep leading zeros. That's correct mathematically but surprising when you're reading bytes:

Input Tool output As a full byte
7f 1111111 01111111
0f 1111 00001111
2C 101100 00101100
F0 11110000 11110000
800 100000000000 0000100000000000 as 16 bits

The rule for fixing it: a hex value of n digits should give 4n bits. If the output is shorter, add zeros on the left until it isn't. Skip this step and every bit position you count from the left will be off.

Worked example: decoding TCP flags

The TCP header has an 8-bit field of control flags. In RFC 9293 they run, from the high bit to the low bit: CWR, ECE, URG, ACK, PSH, RST, SYN, FIN. Packet tools often print this byte in hex. Suppose you see 0x12:

  1. Drop the prefix and convert 12. The tool returns 10010.
  2. Pad to 8 bits: 00010010.
  3. Line the bits up with the flag names:
CWR ECE URG ACK PSH RST SYN FIN
0 0 0 1 0 0 1 0

ACK and SYN are set, so this is the SYN-ACK of a TCP handshake. Without padding, the five-digit output would have lined the 1s up under the wrong flags entirely.

The same method works for any bitmask: file mode bits, CPU status registers, or permission masks stored as hex in a database.

What it accepts and rejects

Input Result
DEADBEEF 32 bits: 11011110101011011011111011101111
ff 11111111 (outer spaces trimmed)
0x1f Error: remove 0x
de ad Error: remove the space
20000000000000 Error: too large (above 53 bits)
empty Output cleared, no error

The 53-bit cap exists because the conversion runs on JavaScript numbers, which are exact only up to Number.MAX_SAFE_INTEGER. Everything happens in your browser; nothing is uploaded.

Related tools

  • Binary to hex compresses bits back into hex digits, four at a time.
  • Hex to decimal gives the value as an ordinary number instead of bits.
  • Hex to text is the right tool if your hex is a run of encoded characters rather than a single number.
  • The random hex generator is handy for producing practice values.

Last updated

Frequently asked questions

How do you convert hex to binary?
Replace each hex digit with its 4-bit pattern and join them. A is 1010 and 5 is 0101, so A5 is 10100101. No arithmetic is needed because one hex digit always equals exactly four bits.
Why does 7f give 1111111 with only seven digits?
The tool outputs the number's shortest binary form, which drops leading zeros. 7f is 01111111 as a full byte. Count the digits and pad with zeros on the left to reach 8, 16 or 32 bits.
Can I paste 0x-prefixed or space-separated hex?
No. Only the characters 0-9 and a-f (either case) are allowed, with optional whitespace at the start and end. Remove 0x and any spaces or colons first, or you'll see "Enter a valid hexadecimal number".
Can it convert a long hex string like a hash?
Only up to 1fffffffffffff (53 bits). A SHA-256 hash is 256 bits, far beyond that, and returns "That number is too large to convert precisely." For long strings, expand the digits by hand with the table on this page, or convert a few digits at a time and pad each piece to 4 bits per digit.