How to Convert Hex to Binary
Converting hexadecimal to binary is one of the most straightforward base conversions in computing. Because hexadecimal is base-16 and binary is base-2, and because 16 is a perfect power of 2 (16 = 24), every single hex digit maps directly to exactly 4 binary bits. No arithmetic is needed — just a simple lookup and substitution.
Step-by-Step Conversion Method
Follow these steps to convert any hexadecimal number to binary by hand:
Step 1: Write down the hex number
Remove any prefix such as 0x or #. For example, 0x2F becomes 2F.
Step 2: Replace each hex digit with its 4-bit binary equivalent
Use the mapping table: 0=0000, 1=0001, 2=0010, 3=0011, 4=0100, 5=0101, 6=0110, 7=0111, 8=1000, 9=1001, A=1010, B=1011, C=1100, D=1101, E=1110, F=1111.
Step 3: Combine all 4-bit groups
Concatenate the binary groups from left to right. The result is the full binary representation.
Why Each Hex Digit Equals 4 Binary Bits
The mathematical relationship is simple: a single hexadecimal digit can represent values from 0 to 15, which is exactly the range of 4 binary bits (). This means:
Each hex digit maps to exactly one 4-bit binary nibble. This perfect power-of-2 relationship is why hexadecimal became the preferred shorthand for binary data in computing, rather than decimal or octal.
Two hex digits represent one byte (8 bits), four hex digits represent a 16-bit word, and eight hex digits represent a 32-bit word. This clean alignment makes hex-to-binary conversion trivially mechanical.
Hex to Binary Conversion Examples
Below are worked examples showing the hex to binary conversion process step by step, from simple single-byte values to multi-byte color codes.
Convert 2F to Binary
Hex input: 2F
1.
2.
3.
Decimal equivalent: 47
Convert 4FA to Binary
Hex input: 4FA
1.
2.
3.
4.
Decimal equivalent: 1,274
Convert FF to Binary
Hex input: FF
1.
2.
3.
Decimal equivalent: 255 — the maximum value of a single unsigned byte (8 bits all set to 1).
Convert Color Code #3A7BD5 to Binary
Hex input: #3A7BD5 (a shade of blue)
1.
2.
3.
4.
5.
6.
7.
The 24-bit result breaks into three bytes: R=00111010 (58), G=01111011 (123), B=11010101 (213). You can also convert hex color codes using our hex to RGB converter.
Hex to Binary Conversion Table
This complete hex to binary conversion table covers all 256 byte values from 00 to FF. Each row shows the hexadecimal value, its decimal equivalent, and the 8-bit binary representation.
Quick Reference (Single Hex Digits 0-F):
| Hex | Decimal | Binary |
|---|---|---|
| 00 | 0 | 00000000 |
| 01 | 1 | 00000001 |
| 02 | 2 | 00000010 |
| 03 | 3 | 00000011 |
| 04 | 4 | 00000100 |
| 05 | 5 | 00000101 |
| 06 | 6 | 00000110 |
| 07 | 7 | 00000111 |
| 08 | 8 | 00001000 |
| 09 | 9 | 00001001 |
| 0A | 10 | 00001010 |
| 0B | 11 | 00001011 |
| 0C | 12 | 00001100 |
| 0D | 13 | 00001101 |
| 0E | 14 | 00001110 |
| 0F | 15 | 00001111 |
This table covers all possible single-byte hexadecimal values (00-FF) with their decimal and 8-bit binary equivalents. For values beyond FF, simply apply the same 4-bit substitution to each hex digit.
Hex to Binary in Programming
Most programming languages provide built-in functions for converting between hexadecimal and binary. Here are examples in the three most popular languages.
Python
# Convert hex string to binary string
hex_value = "FF"
binary_value = bin(int(hex_value, 16))
print(binary_value) # '0b11111111'
# Remove '0b' prefix and pad to 8 bits
binary_clean = bin(int(hex_value, 16))[2:].zfill(8)
print(binary_clean) # '11111111'
# Format with 4-bit groups
hex_value = "3A7BD5"
binary_str = bin(int(hex_value, 16))[2:].zfill(len(hex_value) * 4)
grouped = ' '.join([binary_str[i:i+4] for i in range(0, len(binary_str), 4)])
print(grouped) # '0011 1010 0111 1011 1101 0101'JavaScript
// Convert hex string to binary string
const hexValue = "FF";
const binaryValue = parseInt(hexValue, 16).toString(2);
console.log(binaryValue); // '11111111'
// Pad to 8 bits
const padded = binaryValue.padStart(8, '0');
console.log(padded); // '11111111'
// For large hex values, use BigInt
const bigHex = "3A7BD5";
const bigBin = BigInt("0x" + bigHex).toString(2).padStart(bigHex.length * 4, '0');
console.log(bigBin); // '001110100111101111010101'Java
// Convert hex string to binary string
String hexValue = "FF";
String binaryValue = Integer.toBinaryString(Integer.parseInt(hexValue, 16));
System.out.println(binaryValue); // "11111111"
// Pad to 8 bits
String padded = String.format("%8s", binaryValue).replace(' ', '0');
System.out.println(padded); // "11111111"
// For larger values, use Long
String bigHex = "3A7BD5";
String bigBin = Long.toBinaryString(Long.parseLong(bigHex, 16));
System.out.println(bigBin); // "1110100111101111010101"Key Features
- Instant hex to binary conversion with real-time validation
- Comprehensive hex to binary conversion process visualization
- Clear error messages for invalid hexadecimal inputs
- Optional digit grouping for enhanced binary number readability
- Support for converting any length of hexadecimal numbers to binary
- Automatic decimal equivalent display with smart formatting
- Step-by-step hex to binary conversion breakdown
Applications
- Digital circuit design and analysis requiring hex to binary conversions
- Computer memory debugging using hex to binary representation
- Binary data manipulation in programming with hex to binary conversion
- Assembly language programming and machine code analysis
- Educational purposes for understanding hex to binary number systems
- Color code conversions in web development (e.g., hex to RGB)
Related Converters
Explore our other number system and encoding converters for related tasks:
- Hex to Decimal Converter — Convert hexadecimal numbers to decimal (base-10) values
- Hex to RGB Converter — Convert hex color codes to RGB values for web design
- Hex to Text Converter — Decode hexadecimal strings into readable ASCII text
- Binary to Decimal Converter — Convert binary numbers to decimal representation
- Binary to Octal Converter — Convert binary numbers to octal (base-8) values
- Binary Translator — Translate between binary and text in both directions
- ASCII Converter — Convert between ASCII characters and their numeric codes
- Base64 Encoder/Decoder — Encode and decode data in Base64 format
For a deep dive into the theory and practice of hex-to-binary conversion, read our comprehensive guide: Hex to Binary Conversion: Complete Guide with Table & Examples.