Hex to Binary
Paste hex numbers, one per line, with or without 0x. Get the bits, in groups of 4 if you like. Nothing leaves your browser.
Also: All bases, Hex to Dec, Dec to Hex, Bin to Dec, Dec to Bin, Bin to Hex
- 0
- Numbers
- 0
- Max bits
- 0
- Errors
On this page
About Hex to Binary
Updated
Hex to Binary writes hex numbers as bits. Paste one, or a list of addresses, colors, masks or error codes. Each line is converted, and Steps shows each hex digit with its 4 bits.
Turn on Groups to read the bits in fours, the same way the hex digits split them. Set Signed to a width to keep every leading zero: 1A in 16 bits is 0000 0000 0001 1010.
The same tool, set up for other bases: Hex to Decimal, Decimal to Hex, Binary to Decimal, Decimal to Binary, Binary to Hex, Number Base Converter.
How to use it
- Paste hex numbers, one per line, or load a file. Commas, tabs and semicolons also split a line, so a column from a spreadsheet works.
- Check From and To, next to Convert. On a phone they are under More.
- Press Convert (Alt C). Results shows every number in the To base and in decimal, hex, binary and octal. Output shows only the answers, line for line, for Copy and Download.
- Open Steps to see the math for one number, the way you would do it on paper.
- Swap (Alt S) puts the answers in the editor and turns From and To around, so you can check the way back.
- In Options: Signed for two's complement, Groups for 1111 0000 or 4,294,967,295, Prefix for 0x, 0b or 0o, and how many digits a fraction gets.
How to convert hex to binary by hand
Look up each hex digit in the chart below and write its 4 bits. Put the groups together in the same order:
Hex 3 F A 9
Bits 0011 1111 1010 1001
3FA9 = 0011 1111 1010 1001 = 11111110101001Hex to binary chart
Hex Binary Hex Binary Hex Binary Hex Binary
0 0000 4 0100 8 1000 C 1100
1 0001 5 0101 9 1001 D 1101
2 0010 6 0110 A 1010 E 1110
3 0011 7 0111 B 1011 F 1111Negative numbers and two's complement
A hex number with a minus sign has no bits of its own until you pick a width. Set Signed to 16-bit and -1A becomes 1111 1111 1110 0110.
How two's complement works, with a table and the method by hand.
Exact for big numbers
Each hex digit maps to 4 bits, so FFFFFFFFFFFFFFFF gives 64 ones here. A converter that goes through JavaScript numbers rounds it first and gives a 1 with 64 zeros.
Why other converters round past 2^53.
Common errors
A letter that is not hex
Hex uses 0 to 9 and A to F. A G or a Z often comes from a typo, or from a number in another base. The tool marks the letter and says which base would have it.
1A3G5
G is not a hex digit. Hex uses 0 to 9 and A to F. Remove the G,
or set From to base 17 or more.1A3F5The letter O for a zero
Typed by hand, a capital O and a zero look the same. The tool names the letter, so you know what to type.
12O4
The letter O is not a digit. Type the digit 0 (zero) in its place.1204Two numbers on one line
Spaces inside a number are digit groups: 1111 0000 is one number. When the groups are not the same size, the tool still reads one number but marks the line, because it may be a list.
FF 1A 7
Read as one number, FF1A7. If these are separate numbers, put each on
its own line or split them with commas.FF, 1A, 7Most converters glue two lines into one number with no warning: 1F on one line and 2A on the next become 1F2A, which is 7978.
A number too big for its bits
With Signed set to a width, every number must fit in it. 8 bits are two hex digits, so a third digit is too many.
1FF (Signed: 8-bit)
1FF does not fit in 8 bits. 8 bits hold up to FF in hex.
Pick a wider Signed setting, or set it to Off.Hex to binary in code and Excel
JavaScript parseInt("3f", 16).toString(2) // "111111"
BigInt("0x" + hex).toString(2) // any length
Python bin(int("3f", 16)) # '0b111111'
format(int("3f", 16), "08b") # '00111111'
C printf("%lb", strtol("3f", NULL, 16)) // 111111, C23 only
Java Integer.toBinaryString(Integer.parseInt("3f", 16)) // "111111"
Excel =HEX2BIN("3F") → 111111
=HEX2BIN("3F", 8) → 00111111HEX2BIN works only up to 1FF, because the answer must fit in 10 bits. A negative number, from FFFFFFFE00 to FFFFFFFFFF, comes back as 10 bits.
Hex to binary resources
- Nibble on WikipediaThe 4-bit half of a byte, and why one hex digit names exactly one nibble.
- Hexadecimal on WikipediaWhy programmers write in base 16, the prefixes in each language, and how hex maps to bits.
- Web colors on WikipediaHow #RRGGBB codes work: one byte, two hex digits, for each of red, green and blue.
- Python: bin()bin(25) gives '0b11001'. Use format(25, "08b") for 8 bits with no prefix.
- Microsoft: HEX2BIN functionHex to binary in Excel, only up to 1FF, because the answer must fit in 10 bits.
Hex to binary FAQ
How do I convert hex to binary?
Write each hex digit as 4 bits and put them together. 0 is 0000, 9 is 1001, A is 1010 and F is 1111. There is no math across digits, because 16 is 2 to the power of 4.
For 3F: 3 is 0011 and F is 1111, so 3F is 0011 1111, or 111111 without the leading zeros.
What is FF in binary?
FF is 11111111: F is 1111, twice. It is one full byte, 255 in decimal.
Why is one hex digit always 4 bits?
Four bits have 2 × 2 × 2 × 2 = 16 patterns, from 0000 to 1111, and hex has 16 digits. So each hex digit names one pattern of 4 bits, and two hex digits name one byte. That is why programmers read binary data in hex.
Should the leading zeros stay?
As a number, 0011 1111 and 111111 are the same: 63. In a byte or a register, the zeros show the width, so keep them. Set Signed to 8, 16, 32 or 64 bits to pad every answer to that width, and turn on Groups to split the bits in fours.
Can I convert a hex color to binary?
Yes. Paste #FF5733 as it is: the # is read as hex. With Groups on you get 1111 1111 0101 0111 0011 0011: the first 8 bits are red, then green, then blue.
Are my numbers sent anywhere?
No. The numbers are converted in your browser, with JavaScript BigInt. Nothing is uploaded, and there are no ads or cookie walls. You can check this in your browser's network tab while you use it.