GameParticles
Numbers & units

What Is Hexadecimal? Base 16 and Hex to Decimal Explained

Hexadecimal is a base 16 number system using digits 0 to 9 and letters A to F. Learn how to convert hexadecimal to decimal and why programmers use hex.

Updated

Hexadecimal, or hex, is a base 16 number system. It uses sixteen digits: 0 to 9, then the letters A to F for the values ten to fifteen. Each position is worth sixteen times the one to its right, so hex 2F means 2 sixteens plus 15 ones, which is 47 in decimal.

The sixteen hex digits

Decimal runs out of digits at 9 and carries into a new column. Hex keeps going for six more values before it carries, borrowing letters to stand in for them. Upper and lower case mean the same thing, so ff and FF are equal.

HexDecimalBinaryHexDecimalBinary
000000881000
110001991001
220010A101010
330011B111011
440100C121100
550101D131101
660110E141110
770111F151111

After F comes 10, which is sixteen. Counting continues 11, 12 up to 1F (thirty-one), then 20 (thirty-two).

Hexadecimal to decimal

Each position in a hex number is a power of 16. From the right, the place values are 1, 16, 256, 4,096, 65,536 and so on.

  1. Write the place values under the digits, starting with 1 on the right.
  2. Replace any letters with their values: A is 10, B is 11, C is 12, D is 13, E is 14, F is 15.
  3. Multiply each digit by its place value.
  4. Add the results.

Worked example: convert 7E9.

  • 7 × 256 = 1,792
  • E is 14, and 14 × 16 = 224
  • 9 × 1 = 9

Adding them gives 1,792 + 224 + 9 = 2,025.

Two smaller ones to check your understanding: FF is 15 × 16 + 15 = 255, and 1A3 is 256 + 160 + 3 = 419.

Decimal to hexadecimal

Go the other way by dividing by 16 and collecting remainders, the same idea as the divide by 2 method in Decimal to Binary.

For 2,025: dividing by 16 gives 126 with remainder 9. Dividing 126 by 16 gives 7 with remainder 14, which is E. Dividing 7 by 16 gives 0 with remainder 7. Read the remainders from last to first: 7E9.

Hex and binary fit together

Sixteen is 2 to the power 4, which means one hex digit covers exactly four bits. That is the real reason hex exists. To convert binary to hex, split the bits into groups of four from the right and swap each group for its digit from the table above.

11010110 splits into 1101 and 0110. Those are D and 6, so the byte is D6. Going back is just as mechanical: 3B is 0011 then 1011.

A byte is eight bits, so it is always exactly two hex digits, from 00 to FF. A 32-bit value is eight hex digits. Compare that with decimal, where a byte takes one to three digits and you cannot see the bits at all. For the full method of turning bits into decimal values, see Binary to Decimal.

Why programmers use hex

Hex is the standard shorthand for raw binary data. The places you are most likely to meet it:

  • Colors. A web color such as #FF6600 is three bytes: red FF (255), green 66 (102) and blue 00 (0). The guide to HEX, RGB and HSL color codes goes through this in detail, and the Color Converter translates between the formats.
  • Memory addresses. Debuggers and crash reports print addresses such as 0x7FFE4A10. Memory is laid out in power of two blocks, so boundaries that look arbitrary in decimal are round numbers in hex: 4,096 is 0x1000 and 65,536 is 0x10000.
  • Byte dumps and file formats. Hex editors show each byte as two digits. Every PNG file starts with the bytes 89 50 4E 47.
  • Network identifiers. A MAC address is six bytes written as twelve hex digits, and IPv6 addresses are written as groups of four hex digits.
  • Hashes and IDs. SHA-256 digests and UUIDs are long binary values printed in hex.
  • Character codes. Unicode code points are written in hex, so the letter A is U+0041.

How to tell a number is hex

Because 10 could be ten or sixteen, hex numbers are usually marked.

MarkerWhere it is usedExample
0x prefixC, C++, Java, JavaScript, Python and most languages0x1F
# prefixCSS and design tools, for colors#1F2937
h suffixSome assembly languages1Fh
&#x prefixHTML character referencesA
Subscript 16Math textbooks1F with a small 16

Using the converter

The Number Base Converter keeps hex, decimal, binary and octal fields in sync. Type into the hexadecimal field and the decimal value updates as you type, with the binary form grouped in fours so you can see each hex digit's bits. Enter the digits only, without a 0x or # in front, and in either case. Hex output is shown in capitals.

The converter works with whole numbers up to 32 bits, so the largest hex value it takes is FFFFFFFF, which is 4,294,967,295. That covers bytes, color codes and 32-bit addresses. A full 64-bit address is too long for it, so convert those in two halves or by hand with the place value method.

If you are new to bits and bytes, How to Read Binary starts from the beginning.

Try it

Type 7E9 into the hex field of the Number Base Converter and confirm the decimal reads 2025. Then enter FF, 100 and FFFF and watch where the binary digits roll over. More converters are in the numbers category.

Tools in this guide

Frequently asked questions

How do you convert hexadecimal to decimal?

Multiply each hex digit by its place value and add the results. Place values are powers of 16: 1, 16, 256, 4,096 and so on, from right to left. For 2F, that is 2 times 16 plus 15, which equals 47.

What does 0x mean in front of a number?

It is a prefix that marks the number as hexadecimal in C, JavaScript, Python and many other languages. 0x10 means hex 10, which is decimal 16, not ten. Without a marker like this, there would be no way to tell hex 10 from decimal 10.

Why do programmers use hexadecimal instead of binary?

One hex digit stands for exactly four bits, so a byte is always two hex digits. That makes hex four times shorter than binary while still showing the bit pattern clearly. Decimal is shorter too, but its digits do not line up with bits.

What is FF in hexadecimal?

FF is 255 in decimal: 15 times 16 plus 15. It is the largest value one byte can hold, which is why it appears so often, for example as the maximum for each channel in a color code such as #FF0000.

More numbers & units guides

JSON Formatter
Developer · Format, validate and minify JSON with syntax highlighting.
↵
Base64 Encode / Decode
Developer · Encode text to Base64 or decode Base64 back to plain text.
↵
URL Encoder / Decoder
Developer · Encode or decode URL components and query strings.
↵
Hash Generator
Developer · Generate MD5, SHA-1, SHA-256 and SHA-512 hashes.
↵
UUID Generator
Developer · Generate UUIDs v4 (random) in bulk with one click.
↵
Regex Tester
Developer · Test regular expressions against text with live match highlighting.
↵
Word Counter
Text · Count words, characters, sentences, paragraphs and reading time.
↵
Case Converter
Text · Convert text between UPPER, lower, Title, camelCase, snake_case and more.
↵
List Sorter
Text · Sort, reverse, deduplicate and shuffle lists of text.
↵
Markdown Preview
Text · Write Markdown and see a live rendered preview side by side.
↵
Percentage Calculator
Numbers · Calculate percentages, increases, decreases and what % one number is of another.
↵
Color Converter
Colors · Convert colors between HEX, RGB, HSL and HSV instantly.
↵
Snake
Arcade · Eat food, grow longer, don't hit the walls. A timeless classic.
↵
2048
Puzzle · Slide tiles and combine them to reach the legendary 2048 tile.
↵
Word Grid
Puzzle · Guess the hidden five letter word in six tries using color clues.
↵
Sudoku
Puzzle · Fill the 9x9 grid with logic. Four difficulties from easy to expert.
↵
Minesweeper
Strategy · Use number clues to clear the minefield. Classic logic, three levels.
↵
Breakout
Arcade · Smash every brick with paddle and ball. Power-ups, combos, endless levels.
↵
Typing Practice
Casual · Build your WPM and accuracy with timed drills from 30 seconds to 5 minutes. Find your weak keys.
↵
TypeRunner
Arcade · Multiplayer typing race. Race friends by link, beat computer runners, or chase your own ghost.
↵
Typing Blocks
Arcade · Type each word before its wooden block lands. Miss, and the pile climbs toward the line.
↵
Bubble Shooter
Arcade · Aim, bank shots off the walls, and pop groups of three or more bubbles.
↵
Road Rush
Arcade · Race seven rivals through traffic and punch your way to the front.
↵