Hex to Binary Converter
Enter a hex value and see its binary and decimal equivalents. This simplified version accepts the digits 0 to 9.
What the converter returns
Type a string of hex digits and the tool returns two values: the binary expansion and the decimal value. The default entry is 255, which the converter reads as three hex digits rather than as the number two hundred fifty-five. That produces 597 in decimal and 1001010101 in binary. Each character is fed through the same four-bits-per-digit rule, so the output length is always four times the digit count before leading zeros are stripped.
Why one hex digit is exactly four bits
Hexadecimal is base 16 and binary is base 2. Because 16 = 24, the sixteen hex symbols 0–9 and A–F line up one-to-one with the sixteen patterns that four bits can hold. There is no remainder and no carry between digits, which is what makes the conversion a lookup rather than an arithmetic problem.
This also explains why hex exists at all. Four bits is an awkward width to read and write, while one hex character carries the same information in a single glyph. A 32-bit register prints as 8 hex characters instead of 32 binary digits, and a 64-bit address prints as 16 instead of 64.
The full digit table
| Hex | Binary | Hex | Binary |
|---|---|---|---|
| 0 | 0000 | 8 | 1000 |
| 1 | 0001 | 9 | 1001 |
| 2 | 0010 | A | 1010 |
| 3 | 0011 | B | 1011 |
| 4 | 0100 | C | 1100 |
| 5 | 0101 | D | 1101 |
| 6 | 0110 | E | 1110 |
| 7 | 0111 | F | 1111 |
Read any hex string by substituting each row in order without changing the sequence. The pattern for 2 is 0010, for 5 it is 0101, so 255 expands to 0010 0101 0101 and drops to 1001010101 once the leading zeros go. Nothing is added or reversed.
Worked example with the default input
The input box holds 255. The converter walks the string left to right, multiplying a running total by 16 before adding each digit value: 0 × 16 + 2 = 2, then 2 × 16 + 5 = 37, then 37 × 16 + 5 = 597. That running-total method is exactly what the decimal output shows.
The binary side works digit by digit instead. 2 gives 0010, 5 gives 0101, and the second 5 gives another 0101. Concatenating yields 001001010101, which is 10 significant bits after the two leading zeros are dropped, and those bits weigh 512 + 64 + 16 + 4 + 1 = 597. The two outputs agree, which is the check you want.
If you intended the decimal number 255, the hex form is FF, not 255. FF expands to 1111 1111 and equals 128 + 64 + 32 + 16 + 8 + 4 + 2 + 1 = 255. That is the single most common surprise with this tool.
Where hex-to-binary shows up in practice
- Memory dumps and debuggers, where a 4-byte word prints as 8 hex characters and expands to 32 bits
- Color codes such as #FF8800, where each pair of hex digits is one 8-bit channel (255, 136, 0)
- Network masks and MAC addresses, where each pair of hex digits is one octet
- Bitmask flags in permissions and hardware registers, written in hex to keep the bit columns aligned
In every one of those cases the grouping is by byte, not by the whole string. Splitting on pairs and converting each pair independently gives the same result as converting the full string, which is why you can decode a 6-digit color code one channel at a time without touching the others.
Leading zeros and fixed-width output
The converter trims leading zeros, so hex 0F comes back as 1111 rather than 00001111. That is fine for value comparisons but wrong when bit positions matter. A hardware register, a subnet mask or a fixed-width protocol field needs the zero padding preserved: an 8-bit field written 0F must stay 00001111 so bit 4 keeps its place.
To recover the padded form, expand every digit to four bits and keep all of them. Three hex digits always give 12 bits, so 00F becomes 000000001111 rather than 1111. Use the trimmed form when you want a number and the padded form when you want a bit layout.
Limits of this simplified converter
- Digits 0 through 9 only: the input is a number field, so A–F cannot be typed even though the algorithm would accept them
- No 0x prefix and no spaces: strip both before pasting a value from a debugger
- Inputs above 999999 are rejected by the field, which caps the string at six hex digits and 24 bits
- Negative values are not handled; convert the two’s complement separately if you need signed output
- Fractional hex such as 1.8 is truncated to 1 before conversion
For a hex value containing letters, use a general base converter, or convert the letters by hand with the table above. The arithmetic does not change: A is 10, F is 15, and each still occupies four bits.
Checking the answer by hand
Two independent checks catch nearly every mistake. First, count the bits: a three-digit hex string cannot produce more than 12 bits or fewer than 9 after trimming, because 212 = 4096 and 28 = 256. Second, convert the binary back by grouping from the right in fours and reading each group as a hex digit. If the grouping does not reproduce the input, a digit was dropped or a pair was misread.
Precision and number size
JavaScript stores these integers as doubles, which are exact up to 253. A 13-digit hex string reaches 252, so the ceiling of this tool at six digits leaves a wide margin before any rounding could appear. If you extend the same method to 64-bit hashes, keep the digits in a BigInt or a byte array rather than a double, or the low bits will quietly round off above 253.
Frequently asked questions
How do I convert hex to binary?
Replace each hex digit with its four-bit pattern and keep the order. Hex 2 is 0010 and hex 5 is 0101, so 25 becomes 00100101, or 100101 after trimming the leading zeros.
Why does one hex digit equal four bits?
Because 16 = 24. Four bits hold exactly sixteen distinct patterns, so each hex symbol maps to one pattern with no overlap and no gaps.
Does this calculator support the letters A to F?
No. The input is a number field, so only 0 through 9 can be entered. For A–F use a general base converter; the four-bits-per-digit rule still applies, with A = 1010 through F = 1111.
Why does entering 255 give 597?
The tool reads 255 as three hex digits, not as the decimal number. The arithmetic is 2 × 256 + 5 × 16 + 5 = 597, and the binary output is 1001010101. To convert decimal 255, enter FF instead.
What is hex FF in binary?
FF expands to 1111 1111, which is 8 bits and equals 255 in decimal. Each F is four set bits, so two Fs fill one byte completely.
How many bits is a 6-digit hex color?
24 bits, or 3 bytes. Each of the three channel pairs is 8 bits: #FF8800 is 11111111 10001000 00000000, giving channels 255, 136 and 0.
Why did my leading zeros disappear?
The converter trims them because they do not change the value. If you need a fixed width, expand every digit to four bits and keep all of them, so 0F stays 00001111 rather than 1111.
How many hex digits fit in one byte?
Exactly two. One byte is 8 bits, and two hex digits are 2 × 4 = 8 bits, which is why hex dumps and MAC addresses are written in pairs.
What is the largest value this tool accepts?
The field caps input at 999999, which is six hex digits or 24 bits, so the largest representable value is hex 999999 = 10066329 in decimal.
Can I convert binary back to hex the same way?
Yes. Group the binary digits in fours from the right, pad the leftmost group with zeros, then read each group as one hex digit. 101101 becomes 0010 1101, which is 2D.
Method and sources
- Hex is base 16; 16 = 2⁴, so each hex digit represents four binary bits.