One digit, four bits
Hex and binary fit together neatly because 16 is 2⁴. Every hex digit stands for exactly four binary digits, called a nibble, so you never need arithmetic to convert. You look up each digit and write its four bits in order.
| 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 |
The tool highlights the rows your input uses, so you can follow along.
Example: 0x3F9A
- 3 → 0011
- F → 1111
- 9 → 1001
- A → 1010
Joined: 0011 1111 1001 1010, which is 16,282 in decimal. Keep the leading zeros inside each group. Dropping the zeros from 3 would shift every later bit and change the number.
Remembering the table
You don't need to memorize all sixteen rows. The four bit positions are worth 8, 4, 2 and 1 from left to right. Break a digit into those values and set the matching bits:
- 9 = 8 + 1 → 1001
- A (10) = 8 + 2 → 1010
- D (13) = 8 + 4 + 1 → 1101
- 6 = 4 + 2 → 0110
Grouping and padding
Group bits changes only how the output is spaced:
- by 4 matches the hex digits one to one and is easiest to check;
- by 8 shows whole bytes, which suits network and file-format work;
- no spaces gives a single string to paste into code (
0b0011111110011010).
Pad to fills the result to a fixed width with leading zeros, such as 16 or 32 bits. That's useful when the value is a register or a field with a defined size and you need to see exactly which bit positions are set. If the number is wider than the width you picked, the tool tells you instead of cutting bits off.
Reading bit flags
Hex is how most documentation writes bit masks, while binary shows which flags are on. A Unix file mode such as 0x1ED becomes 0001 1110 1101. The low nine bits, 111 101 101, are the familiar rwxr-xr-x (755 in octal).
Another example: in many microcontroller datasheets a control register of 0xA5 reads 1010 0101, so bits 7, 5, 2 and 0 are set. Counting from the right, starting at 0, is the usual convention.
Colors in binary
A HEX color is three bytes, so #D9481C in binary is:
- D9 → 1101 1001 (red, 217)
- 48 → 0100 1000 (green, 72)
- 1C → 0001 1100 (blue, 28)
That's 24 bits in all, which is where the name "24-bit color" comes from, along with its 16,777,216 possible values.
Accepted input
You can include a 0x prefix, spaces or underscores, and use either case. Invalid characters are reported. There's no length limit worth worrying about: a 64-character SHA-256 hash converts to 256 bits instantly. The decimal readout uses BigInt, so it stays exact.
Related tools
The reverse conversion is on binary to hex. For the decimal value with a full place-value table, use hex to decimal. For bitwise AND, OR and XOR between two values, open the hex calculator.
FAQ
How many bits is a hex digit?
Four. Two hex digits make one byte (8 bits), which is why bytes are usually written as pairs like 3F.
Why do programmers prefer hex over binary?
It's four times shorter and still converts to bits without any math. 0xFFFF is much easier to read and type than sixteen ones.
Is octal related too?
Yes. Each octal digit is exactly three bits, which is why Unix permissions (three bits each for owner, group and others) are written in octal. Hex took over for most other uses because bytes are 8 bits, which splits evenly into two hex digits but not into octal ones.