Hex to Binary Converter

Hex to binary converter: each hex digit becomes four bits, so 2F3 is 0010 1111 0011. Enter a value or a list, with or without 0x, and choose groups of four or a 0b prefix. Values of any length convert exactly in your browser.

Hex to binary
1 value
10 digits out
Prefixes, underscores and spaces are accepted · your input stays in this browser
Each digit of 2F3 as four bits
Hex digitValue4 bits
220010
F151111
330011

Hex to binary: replace each digit with four bits

No arithmetic is needed to convert hexadecimal to binary. Sixteen is 2^4, so every hex digit stands for exactly four binary digits, and the conversion is a lookup: write each digit as its four-bit group and join the groups. 2F3 is 2, F and 3, which are 0010, 1111 and 0011, so the binary is 0010 1111 0011. Leading zeros in front of the first 1 can be dropped, leaving 1011110011.

2F3 as bits2 is 0010, F is 1111, 3 is 0011. Joined, 2F3 is 0010 1111 0011.2= 20010F= 1511113= 30011
Each hex digit is exactly four bits, so 2F3 converts to 0010 1111 0011 without any arithmetic.

The reverse is just as direct: cut a binary string into groups of four from the right and read each group as a digit, which is the method on the binary to hex page. The correspondence is what makes hex the standard shorthand for bits.

Reading the bit weights of a hex digit

If you want to avoid memorizing sixteen groups, learn the weights. The four bits in a group are worth 8, 4, 2 and 1 from left to right. A digit is the sum of the weights where the bit is 1. The digit B is 11 = 8 + 2 + 1, so its bits are 1 0 1 1. The digit 6 is 4 + 2, so its bits are 0 1 1 0. The table shows each digit split into those four columns.

Hex digits by bit weight (a 1 means that weight is added)
Hex8421Sum
000000
100011
200102
300113
401004
501015
601106
701117
810008
910019
A101010
B101111
C110012
D110113
E111014
F111115

With the weights in mind, 9 is 8 + 1 (1001), C is 8 + 4 (1100), and E is 8 + 4 + 2 (1110). F is every weight at once, 15, and 0 is none. Four ones in a row are therefore always F, and 1010 is always A, which is why 10101010 is easy to recognize as AA.

When leading zeros matter

Mathematically 0001 and 1 are the same number, and the converter's default output drops them. Hardware and protocols do not: a field has a fixed width, and the unused high bits are written as zeros. The byte 0x0A is 0000 1010 in an 8-bit field and 0000 0000 0000 1010 in a 16-bit field. When the width matters, turn on groups of four, which pads the first group, and pad further to the field width yourself.

Zeros also decide the meaning when a value is read as signed. In an 8-bit signed integer the byte 0x80 is 1000 0000 and means −128, while 0x0080 in 16 bits is 0000 0000 1000 0000 and means 128. The digits are the same; the width of the container is not. The hex to decimal page covers signed readings.

Long hex values: 32-bit and 64-bit numbers

The method scales without change, one digit at a time. A 32-bit value has eight hex digits and 32 bits, and a 64-bit value has sixteen and 64. DEADBEEF, a value used as a recognizable filler in debugging, converts as follows.

DEADBEEF, digit by digit
Hex digitDEADBEEF
4 bits11011110101011011011111011101111

Joined, the 32 bits are 1101 1110 1010 1101 1011 1110 1110 1111. The converter accepts values of any length, including 64-digit hash digests, which come out as 256 bits. A good habit when comparing long bit strings is to switch on the groups of four: it lines up the columns with the hex digits so a mismatch can be located to a digit.

Bits of characters: ASCII letters and UTF-8 lead bytes

Converting character codes to bits shows how text encodings are built. The letter A is 41, which is 0100 0001, and lower case a is 61, 0110 0001: the two differ only in the third bit from the left. The digit 0 is 30, 0011 0000, so the digits start with the bit pattern 0011 followed by their value. Every ASCII byte starts with a 0 bit, because ASCII is a 7-bit code.

UTF-8 uses the leading bits of each byte to say what the byte is, and that is the reason hex ranges in UTF-8 text have meaning. A byte starting with 0 is a complete ASCII character; one starting with 110 begins a two-byte sequence; 1110 begins a three-byte one; 11110 a four-byte one; and a byte starting with 10 is a continuation. Converting the hex ranges to binary gives the table.

UTF-8 byte types by hex range
Hex rangeBinary starts withMeaning
00 to 7F0xxxxxxxOne-byte character (ASCII)
80 to BF10xxxxxxContinuation byte; never the first byte of a character
C2 to DF110xxxxxFirst byte of a two-byte character (C0 and C1 are never valid)
E0 to EF1110xxxxFirst byte of a three-byte character
F0 to F411110xxxFirst byte of a four-byte character (F5 and above never occur)

The table is the reason a hex decoder can report precisely where a UTF-8 string breaks: a byte in the range 80 to BF with no lead byte before it, or a lead byte followed by something that is not a continuation, violates the pattern. The hex decoder reports the byte offset of each such error.

Hex and bit masks

Hex-to-binary conversion is how masks are read. A mask is a number whose 1 bits select positions, usually applied with AND to keep those bits and clear the rest. Writing masks in hex works because each digit controls exactly four positions, so 0F keeps the low four bits and F0 the high four. The table lists masks you will see in source code and network configuration.

Common hex masks and what they select
HexBinary meaningTypical use
01bit 0 onlyTests whether a number is odd
0Flow four bitsKeeps one hex digit, the low nibble
F0high four bitsKeeps the high nibble of a byte
7Flow seven bitsStrips the top bit; keeps a value within ASCII
80top bit of a byteThe sign bit of an 8-bit integer
FFall eight bitsA whole byte
FFFFFF0024 ones, 8 zerosThe IPv4 mask 255.255.255.0, written /24

The last row is a subnet mask. FFFFFF00 is 24 one bits followed by 8 zero bits, which is why 255.255.255.0 is written /24: the number after the slash counts the ones. The same reading applies to flag fields in file formats and protocols: the specification lists a hex value for each flag, such as 0x01 and 0x80, and the binary form shows which bits a set of flags occupies.

Why hexadecimal exists: shorthand for bits

Binary is what hardware stores and unreadable for anything longer than a byte. A 32-bit address in binary is 32 characters and easy to miscount; in hex it is eight. Bytes were 8 bits on most machines from the 1960s, and two hex digits describe a byte exactly, which made base 16 a better fit than the earlier octal, whose digits cover three bits and do not line up with an 8-bit byte. IBM's System/360 family, introduced in 1964, brought hexadecimal into general use.

That is the practical reason for the converter: hex is what you read in debuggers, memory dumps and protocol documents, and binary is what you need when a single bit is the question. Moving between the two is mechanical, and tool support for it is everywhere. The broader picture of the notation is on the hexadecimal page.

Hex to binary in Python, JavaScript, C and the shell

Python
bin(int("2F3", 16))                 # '0b1011110011'
format(int("2F3", 16), "012b")      # '001011110011' (padded to 12 bits)
format(int("DEADBEEF", 16), "032b") # 32 bits with leading zeros kept
JavaScript
parseInt("2F3", 16).toString(2)                // '1011110011'
parseInt("2F3", 16).toString(2).padStart(12, "0")   // '001011110011'
BigInt("0xDEADBEEFDEADBEEF").toString(2)       // exact for 64 bits and beyond
Shell and PowerShell
# Bash has no binary output format, so divide by 2 and collect the remainders
n=$((16#2F3)); b=""; while [ $n -gt 0 ]; do b=$((n%2))$b; n=$((n/2)); done; echo $b   # 1011110011

[Convert]::ToString(0x2F3, 2)                  # 1011110011

C has no standard binary output format, so programs print binary with a loop over the bits, or print the hex and read it with the table above. parseInt on a 16-digit hex string loses the low digits because JavaScript numbers are exact only to 53 bits, so use BigInt for 64-bit values.

Worked examples: A5, 7E and CAFE

A5 is the digits A and 5. A is 10, which is 8 + 2, so its bits are 1010. 5 is 4 + 1, so its bits are 0101. Joined, A5 is 1010 0101, a byte with alternating pairs, and the leading digit is 1 so nothing is dropped. 7E starts with a 7, which is 0111; with the E, 1110, the byte is 0111 1110, and without the leading zero it is the seven digits 1111110.

CAFE is four digits and 16 bits: C is 1100, A is 1010, F is 1111 and E is 1110, so CAFE is 1100 1010 1111 1110. A slower route confirms it: CAFE is 51,966 in decimal, and 51,966 in binary is the same 16 digits. Doing a conversion both ways is worth the extra minute whenever the result is going into a hardware register or a protocol field.

Checking hex to binary results

The length gives a first check. Every hex digit is four bits, so n digits give 4n bits before the leading zeros are dropped. How many zeros drop depends on the first digit alone, and a short table settles it.

Leading zeros dropped by the first hex digit
First digitIts four bitsLeading zeros droppedBits it contributes
1000131
2 or 30010 or 001122
4 to 70100 to 011113
8 to F1000 to 111104

So 2F3, three digits starting with 2, has 12 − 2 = 10 bits, and the answer 1011110011 has ten. A second check counts the ones. The number of 1 bits is the sum of the ones in each digit group, which is easy to tally: F has four, 2 and 3 have one and two, and the total is seven in 1011110011. The strongest check is to convert the binary back to hex by grouping, which should return the original digits.

Reading a status byte bit by bit

Status registers and flag bytes in device documentation define one meaning per bit. A device reports B4 and the manual lists bit 7 as ready, bit 5 as error and bit 2 as busy. The conversion gives B4 = 1011 0100, and numbering the bits from the right, starting at 0, shows which are set.

B4 as eight numbered bits
Bit76543210
Value10110100
Weight1286432168421

The bits that are set are 7, 5, 4 and 2, and the weights 128 + 32 + 16 + 4 add to 180, which is B4 in decimal. Tests in code use the same arithmetic in reverse: status & 0x20 is non-zero when bit 5 is set. The low-digit-first trap applies here: the bit that is rightmost in the binary is bit 0, the least significant, whatever the documentation's drawing order.

Hex to binary in network addresses

Network protocols assign meaning to individual bits of a hex byte. The first byte of a MAC address carries two flags in its lowest bits: the least significant bit says whether the address is unicast (0) or multicast (1), and the next bit says whether it is universally administered (0) or locally administered (1). In the address 02:00:5E:10:00:01 the first byte 02 is 0000 0010, so the address is unicast and locally administered. The prefix 01:00:5E, which starts every IPv4 multicast MAC address, has a first byte of 01, binary 0000 0001, with the multicast bit set.

TCP packs control flags into one byte of the header, and captures print it in hex. Reading it means converting to bits, since each flag is one bit: FIN is 01, SYN is 02, RST is 04, PSH is 08, ACK is 10 and URG is 20.

TCP flag bytes as they appear in a capture
HexBinaryFlags set
020000 0010SYN: the first packet of a connection
120001 0010SYN and ACK: the reply to a SYN
100001 0000ACK: an ordinary acknowledgement
180001 1000PSH and ACK: data pushed to the application
110001 0001FIN and ACK: one side closes the connection
040000 0100RST: the connection is reset
140001 0100RST and ACK

The pattern, a few flags per byte and a different bit for each, is the same in file attributes, CPU status registers and image format headers. Whenever documentation lists masks like 0x01 and 0x80, the binary form shows which bit each one is.

Grouping by three: the octal route

Octal is the same idea with groups of three bits. To go from hex to octal without arithmetic, convert to binary, regroup the bits in threes from the right, and read each group. FF is 1111 1111, which regrouped as 011 111 111 is 377. The two-step path is also the safest way to convert between any two bases that are powers of two (2, 4, 8, 16, 32): through binary, with the grouping size set by the base. The hex converter shows octal alongside the other bases.

Questions about converting hex to binary

How many binary digits is one hex digit?

Four. Sixteen is 2 to the power of 4, so a hex digit has exactly as many values as four bits. Two hex digits are eight bits, one byte.

What is FF in binary?

11111111. F is 1111, and FF is two F digits side by side, so all eight bits of a byte are set. In decimal this is 255.

Why does the output start with zeros?

Only when you turn on groups of four, or enter a value with leading zeros. By default the converter drops the zeros in front of the first 1, as 2F3 gives 1011110011. In fixed-width fields the zeros are kept: 0x00FF is 0000 0000 1111 1111 in 16 bits.

Can I convert a hex string that is not a number, such as a hash?

Yes. A hash is just a long hex number, and the converter handles any length. A 64-digit SHA-256 digest becomes 256 bits. Treating it as text instead is a different job for the hex decoder.

How do I convert hex to binary on a calculator?

Use programmer mode. In the Windows Calculator choose Programmer, select HEX, type the value and read the BIN line. The by-hand method is quicker for short values: replace each digit with its four bits.