How to Convert Hex to Binary
Convert hexadecimal strings to binary representation and understand the relationship between the two.
Problem
You have a hex string (e.g., from a hash digest) and need its binary (0s and 1s) representation for analysis or low-level work.
Prerequisites
- Understanding of hexadecimal (base-16)
- Understanding of binary (base-2)
Steps
-
1. Split the hex into nibbles
Each hex digit (nibble) corresponds to exactly 4 binary bits. Split the hex string into individual characters so you can map each one independently.
Input1AOutputnibbles: 1, A -
2. Map each nibble to 4 bits
Convert each hex digit to its 4-bit binary equivalent: 1 → 0001, A → 1010. Concatenate the results. Do not drop leading zeros in any nibble.
Input1AOutput00011010 -
3. Verify the result
Group the binary output into bytes (8 bits) and confirm each byte matches the original hex pair. 1A in hex equals 26 in decimal, which equals 00011010 in binary.
Input00011010Outputdecimal: 26 ✓
Expected result
A binary string where every hex digit expanded to exactly 4 bits, preserving leading zeros.
Common errors
- Dropping leading zeros in the first nibble
- Always pad each nibble to exactly 4 bits. The hex value 0F must become 00001111, not 1111.
- Including the 0x prefix in the conversion
- Strip the 0x prefix before converting. It is a notation marker, not part of the value.
Troubleshooting
- If the binary length is not 4× the hex length, you dropped a leading zero.
- Use a base converter tool to cross-check the result.
Security limits
- This is a pure format conversion with no security implications.
Related tools
Related glossary
Related tasks
Ready to run it?