Map each hex digit to its 4-bit value, then join the bit groups and trim leading zeros as needed.
Hexadecimal and binary both describe the same thing: numbers. They just use different symbols. Binary uses two symbols (0 and 1). Hex uses sixteen symbols (0–9 and A–F). When you’re reading code, packet dumps, hashes, colors, memory addresses, or file headers, hex is common because it’s compact. When you’re dealing with bit flags, masks, shifts, or low-level storage, binary is easier to read.
Converting hex to binary looks scary until you notice the neat link between them. One hex digit always matches exactly four binary bits. That’s it. Once you learn the 0–F map, the rest is copy-and-paste work with your brain.
Why Hex And Binary Match So Cleanly
Binary is base 2. Hex is base 16. Since 16 equals 2 × 2 × 2 × 2, one hex digit covers four base-2 positions. That’s why you can translate digit by digit without doing long division. Many specs lean on this relationship, and NIST publications describe a hex digit as the representation of a 4-bit string in their notation.
Quick Mental Model
Think of a hex number as a row of “nibbles.” A nibble is 4 bits. Each hex digit is one nibble written with a single character. Convert each character to 4 bits, line them up, and you’ve converted the whole value.
What You Need Before You Start
You only need three small habits:
- Uppercase and lowercase mean the same: A and a both mean 10.
- Keep groups of four: binary output is easiest to check in 4-bit chunks.
- Trim only when it fits the job: dropping leading zeros can break fixed-width data even when the numeric value stays the same.
Hex Digits And Their Values
Hex uses digits 0–9, then letters A–F for values 10–15. That letter mapping matters when you convert. If you mix up B and D, your bits will be wrong, and every later step will look wrong too.
How To Convert Hexadecimal To Binary Step By Step
This is the method you’ll use most of the time. It works for single digits, long strings, and values that start with 0x in programming languages.
Step 1: Write The Hex Value In Clean Groups
Take your hex input and write it without separators. Strip prefixes like 0x if they’re present. Then scan for any character outside 0–9 and A–F. If you spot one, the input isn’t valid hex.
Step 2: Replace Each Hex Digit With Its 4 Bits
Convert each character using the 4-bit map. Do it left to right. Don’t change the order. Each digit becomes four binary digits, even if it starts with zeros.
Step 2A: Build A Nibble With Bit Weights
If you don’t have the map memorized yet, you can still convert each digit using bit weights. A 4-bit nibble has places worth 8, 4, 2, and 1. Write those weights down once, then turn each hex digit into a number from 0 to 15 and “switch on” the weights that add up to it.
Take D, which equals 13. Thirteen is 8 + 4 + 1, so the 8 and 4 positions are 1, the 2 position is 0, and the 1 position is 1. That gives 1101. Take 6. Six is 4 + 2, so the nibble is 0110. This weight trick is slower than the table at first, yet it’s a solid fallback when you’re stuck without a reference.
Step 3: Join The 4-Bit Groups
Once every digit is translated, join the groups into one binary string. Keeping spaces between nibbles while you work helps catch mistakes. Remove the spaces at the end if you need a plain bit string.
Step 4: Trim Leading Zeros Only If You Want A Minimal Number
If the goal is a numeric value, you can drop leading zeros until the first 1. Keep a single 0 if the value is zero. If the goal is a fixed width field (like a byte, word, or 32-bit register), keep the leading zeros that preserve that width.
Hex To Binary Conversion Map You Can Memorize
Use this table as your “one glance” reference. It matches the mapping used in base-16 encoding standards like RFC 4648 Base 16 Encoding, where each character stands for one 4-bit value.
| Hex Digit | Binary (4 Bits) | Decimal Value |
|---|---|---|
| 0 | 0000 | 0 |
| 1 | 0001 | 1 |
| 2 | 0010 | 2 |
| 3 | 0011 | 3 |
| 4 | 0100 | 4 |
| 5 | 0101 | 5 |
| 6 | 0110 | 6 |
| 7 | 0111 | 7 |
| 8 | 1000 | 8 |
| 9 | 1001 | 9 |
| A | 1010 | 10 |
| B | 1011 | 11 |
| C | 1100 | 12 |
| D | 1101 | 13 |
| E | 1110 | 14 |
| F | 1111 | 15 |
Worked Conversions That Show The Pattern
Seeing a few full conversions makes the method stick. Keep the nibble spacing while you work, then compress it at the end.
Example 1: 3A
3 becomes 0011. A becomes 1010. Join them: 0011 1010. As a minimal number, that’s 111010. As a fixed two-nibble value, keep it as 00111010.
Example 2: 0F
0 becomes 0000. F becomes 1111. Join them: 0000 1111. Minimal form is 1111. A full byte form is 00001111.
Example 3: 7C9
7 becomes 0111. C becomes 1100. 9 becomes 1001. Join them: 0111 1100 1001. Minimal form drops the first 0: 11111001001.
How To Handle Prefixes, Spacing, And Fixed Width Data
Real inputs rarely arrive as a clean two-character hex number. You’ll run into 0x prefixes, spaced bytes, or long strings that represent exact byte counts.
Stripping 0x And Similar Prefixes
Many languages print hex values with 0x. That prefix is not part of the number. Remove it before conversion, then convert each remaining digit.
Keeping Byte Boundaries
If your hex string has an even number of digits, it lines up neatly into bytes (two hex digits per byte). After conversion, you can group the binary into sets of 8 bits to match those bytes. This helps when you’re reading file signatures, packet headers, or register dumps.
When Leading Zeros Are Not Optional
Numeric value and stored value are not the same thing. The number 15 can be written as 1111, 00001111, or 0000000000001111. They all mean the same numeric value. They do not all mean the same storage width. If you’re matching a spec, keep the width the spec asks for.
Common Mistakes And Fast Ways To Catch Them
Most conversion errors come from small slips, not hard math. These are the ones that show up most often, plus checks that flag them fast.
Mixing Up Letters And Values
A=10, B=11, C=12, D=13, E=14, F=15. If you swap two of these, your binary will still look valid, which makes the error sneaky. A check is to translate the letter to decimal in your head, then confirm the 4-bit pattern matches that value.
Dropping Zeros In The Middle
Zeros inside the number are part of the value. 10 in hex is 0001 0000 in binary. If you drop the middle zeros and write 0001 1, the value changes. Keep each nibble as four bits until the end.
Reversing Bit Order
Each nibble is written from most-significant bit to least-significant bit. For hex A, the bits are 1010, not 0101. If your output seems mirrored, check for this slip.
Sanity Check With Powers Of Two
Some hex values are easy landmarks. 8 is 1000. 4 is 0100. 2 is 0010. 1 is 0001. If a nibble has a single 1 bit, you can spot it fast.
Handy Shortcuts For Longer Hex Strings
Long strings can feel tedious, yet the same steps hold. A few tricks keep you from losing your place.
Work In Chunks Of Four Hex Digits
Four hex digits equal 16 bits. Convert four digits, write the 16 bits, then move on. This chunking keeps your eyes from sliding across the line.
Keep A Running Group Count
As you convert, mark every four nibbles as a block. If you end up with a block that is not 16 bits, you know a digit was skipped or added.
Use Byte Grouping For Debugging
Two hex digits map to 8 bits. If you’re checking bytes, convert two digits at a time so you can compare byte by byte.
Hex To Binary Output Formats
Binary is not always printed as one long line. Different contexts prefer different layouts. The value stays the same, but the formatting changes.
| Use Case | Binary Layout | Why It Helps |
|---|---|---|
| Minimal numeric form | Drop leading zeros | Shortest readable value |
| Nibble view | Group bits in 4s | Matches hex digits one-to-one |
| Byte view | Group bits in 8s | Lines up with bytes and ASCII |
| Word view | Group bits in 16 or 32 | Matches registers and many specs |
| Prefixed string | Add 0b before bits | Common in code and docs |
| Spaced debug string | Spaces or underscores | Stops misreading long runs |
| Fixed width field | Pad left with zeros | Keeps size stable for parsing |
Quick Practice Drills
If you want speed, practice beats rereading. Try these as short drills. Write the 4-bit nibble for each digit, then join them.
- Drill A: 1F20 → convert each digit → join → group into bytes
- Drill B: BEEF → write nibbles → check each letter value
- Drill C: 00A5 → keep leading zeros as a fixed 2-byte value
When You Should Verify With A Standard
If you’re converting hex that comes from a spec, stick to that spec’s formatting rules. Base-16 encoding rules define valid alphabets and how to treat case. Cryptography specs often define exact bit lengths for fields, which forces you to keep leading zeros. The definitions section in NIST FIPS 180-4 uses the common convention that a hex digit represents a 4-bit string.
One Last Self-Check Before You Move On
Run this checklist after any conversion:
- Did every hex character become exactly 4 bits?
- Did you keep the digit order from left to right?
- Did you trim zeros only at the far left, and only when you wanted a minimal number?
- Did your chosen grouping (4, 8, 16, 32) match the job you’re doing?
Once you can do a few conversions without looking at the table, you’re set. From there, hex dumps and bit fields stop feeling like noise and start reading like structured data.
References & Sources
- IETF.“RFC 4648: Base 16 Encoding.”Defines a standard base-16 alphabet that matches common hex digit to 4-bit mappings.
- National Institute of Standards and Technology (NIST).“FIPS 180-4: Secure Hash Standard.”Defines notation where each hex digit represents a 4-bit string.