Home › Binary to Hexadecimal Conversion

Binary to Hexadecimal Conversion

Hex is shorthand for binary. Group four bits at a time, look up the nibble value, and you have your hex digit. No arithmetic required.

Open a crash log or a color picker and you will see hex, not binary. A 32-bit value like 11001010111100001010111000010110 takes real effort to parse at a glance, and nobody debugging at 2am wants to count 32 digits by hand. Hex fixes that by condensing every four binary digits into one symbol, shrinking that same value to eight characters. The conversion is mechanical and fully reversible, which is why hex became the default notation in programming, debugging, and hardware documentation rather than a competing shorthand.

Hexadecimal Basics: Base 16

Decimal is base 10, using the digits 0 through 9. Binary is base 2, using 0 and 1. Hexadecimal is base 16, which means it needs sixteen distinct digit symbols. The first ten are the familiar 0 through 9. For values 10 through 15, hex borrows letters: A (10), B (11), C (12), D (13), E (14), and F (15).

This matters because a single hex digit can represent values from 0 to 15, which is exactly the range of a 4-bit binary group. That precise alignment between binary and hex is what makes the conversion so clean. There is no rounding, no remainder, no information lost or added.

Hexadecimal numbers are typically prefixed with 0x in code (for example, 0xFF) or suffixed with a capital H in some older assembly notations (FFH). Both mean the same thing. Throughout this guide, the 0x prefix is used.

The Nibble Method

A nibble is a group of four bits. The name is a half-joke: a byte is eight bits, and four bits is half a byte, so it got called a nibble. Each nibble maps directly to one hex digit.

The conversion process has three steps:

  1. Pad the binary number on the left with zeros until its length is a multiple of four.
  2. Split it into groups of four bits, starting from the right.
  3. Replace each group with its hex equivalent using the nibble table below.

That is the entire method. There is no addition or multiplication involved. It is a lookup and substitution, which is why experienced programmers can do it in their heads for short values.

Worked Example 1: Converting 10110100

Start with 10110100. It is already 8 bits, a multiple of four, so no padding is needed.

Split into two nibbles from the right: 1011 and 0100.

  • 1011 in decimal is 8 + 2 + 1 = 11, which is B in hex.
  • 0100 in decimal is 4, which is 4 in hex.

Result: 0xB4.

To verify: 10110100 in binary equals 128 + 32 + 16 + 4 = 180 in decimal. And 0xB4 = (11 x 16) + 4 = 176 + 4 = 180. They match.

Worked Example 2: Converting 11111111

Take 11111111, all eight bits set to 1. Split into two nibbles: 1111 and 1111.

  • 1111 = 8 + 4 + 2 + 1 = 15 = F in hex.
  • 1111 = 15 = F in hex.

Result: 0xFF.

This is probably the most commonly seen hex value in all of computing. In decimal it equals 255, which is the maximum value for an unsigned 8-bit byte. You will encounter 0xFF constantly in web color codes, network masks, and low-level code.

Full Nibble Table

BinaryDecimalHexBinaryDecimalHex
000000100088
000111100199
001022101010A
001133101111B
010044110012C
010155110113D
011066111014E
011177111115F

Hex column cross-checked against the hex field in binary-ascii-reference-2026.csv, the site's ASCII dataset (0x0 through 0xF correspond to the CSV's first sixteen rows).

Print or bookmark this table. After a week of using it regularly, most people find they have memorized it without intending to, at least through the A-F range where the letter substitutions happen.

Hex in Practice

Web Color Codes

The color #3A7DFF is three hex byte pairs. 3A is the red channel (decimal 58), 7D is the green channel (decimal 125), and FF is the blue channel (decimal 255). Each pair represents one byte, ranging from 00 (none of that color) to FF (full intensity).

Memory Addresses

Debuggers display memory addresses in hex because a 64-bit address like 0x00007FFE4B2A0010 is far more readable than its 64-character binary equivalent. Crash dumps, stack traces, and disassembly listings all use hex for this reason.

MAC Addresses

Network interface cards are identified by MAC addresses written as six hex byte pairs separated by colons or hyphens, for example 00:1A:2B:3C:4D:5E. Each pair is one byte (8 bits, two nibbles), so the full address is 48 bits of binary data expressed concisely in twelve hex digits.

File Headers and Magic Numbers

Every PNG image starts with the byte sequence 89 50 4E 47 in hex. PDF files start with 25 50 44 46. These "magic numbers" let software identify file types without relying on the file extension, and hex is the standard notation for inspecting them in a hex editor.

Going Back: Hex to Binary

The reverse conversion is equally simple. Take each hex digit and write out its 4-bit binary equivalent from the nibble table above.

Example: convert 0xC7 to binary.

  • C = 12 = 1100
  • 7 = 7 = 0111

Result: 11000111.

Verification: 128 + 64 + 4 + 2 + 1 = 199 in decimal. And 0xC7 = (12 x 16) + 7 = 192 + 7 = 199. Correct.

One point to watch: always use exactly four binary digits per hex digit. The hex digit 3 is 0011, not 11. Dropping leading zeros inside a nibble position will corrupt the result.

Related Reading

FAQ

Why do programmers use hex instead of binary?

Hex is more compact. One hex digit represents exactly four binary bits, so an 8-bit byte takes two hex digits instead of eight binary digits. The values are directly equivalent, but hex is much faster to read and write. A 32-bit address uses 8 hex digits versus 32 binary digits.

What is a nibble in binary?

A nibble is a group of 4 binary bits. It can represent values from 0000 (0) to 1111 (15), which maps exactly to a single hexadecimal digit (0 through F). Two nibbles make one byte (8 bits).

How do I convert hex back to binary?

Replace each hex digit with its 4-bit binary equivalent from the nibble table. For example, 0xA3 becomes 1010 (A) and 0011 (3), giving 10100011. Always use all four bits per hex digit, including any leading zeros within the nibble.

What does the 0x prefix mean in hexadecimal?

The 0x prefix is a convention used in C, Python, JavaScript, and many other languages to signal that the number that follows is written in base 16. For example, 0xFF equals 255 in decimal and 11111111 in binary. Some older notations use an H suffix instead, such as FFH, but 0x is the dominant modern form.

Does the letter case of hex digits matter?

Not to the value. 0xff and 0xFF are the same number. Most style guides pick one case and stick to it. Uppercase is common in older documentation; lowercase is more common in modern code.

Cookies here just cover analytics and ad delivery, nothing more. Privacy