A computer stores every value as bits, and a byte of eight bits reads as eight digits of 0 and 1. Nobody wants to read a memory address that way, so computers write the same value in hexadecimal: base 16, where each digit stands for exactly four bits. One byte becomes two digits, and a 32-bit address shrinks from 32 characters to eight.
Sixteen digits replace two, and in return every value a machine produces becomes short enough to read at a glance. A color, an address, and an emoji all carry their values in hex, and each one decodes with the same two methods.
What hexadecimal is?
Hexadecimal is the base-16 numeral system. It uses sixteen digits: 0 through 9, then A through F, where A stands for 10, B for 11, C for 12, D for 13, E for 14, and F for 15. Each letter is a digit like any other, and it holds one value that never changes.
Why does hex use letters at all? Base 16 needs sixteen single symbols and we only have ten numerals, so A through F stand in for 10 through 15. A hex number reads left to right like any other number, with each position worth sixteen times the one to its right.
Code marks a hex literal with a 0x prefix, so 0xFF means the hex value FF. The prefix shows up in C, Python, JavaScript, and Java, and it keeps a hex value from being read as a word or a decimal number.
| Hex digit | Decimal value | Four bits |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Why computers use base 16?
A hex digit holds exactly four bits because 16 equals 2 to the power of 4. That fit is the whole reason the system exists: a byte splits cleanly into two hex digits, and no digit is ever wasted on a partial group.
The compression shows up fast. A 32-bit address takes 32 characters in binary and eight in hex. A byte written as 11111111 becomes FF. Four hex digits hold 65,536 distinct values, from 0000 to FFFF.

The CPU works in binary, and hex is how people read the values it produces. Memory dumps, registers, and addresses all print in hex because the people debugging them need to read them quickly. The guide to how a CPU works shows the binary side of that picture.
Decimal to hex, worked
Converting decimal to hex takes repeated division by 16. Divide the number by 16, write down the remainder, and repeat with the quotient until it reaches zero. Then read the remainders from the bottom up.
Why read the remainders backwards? The first remainder is the smallest place value, the rightmost digit, so it goes last. Each division peels off one digit, starting from the right.
Take 2026, the current year. The division table is the whole method, with each remainder turned into its hex digit as it appears.
| Division | Quotient | Remainder | Hex digit |
|---|---|---|---|
| 2026 ÷ 16 | 126 | 10 | A |
| 126 ÷ 16 | 7 | 14 | E |
| 7 ÷ 16 | 0 | 7 | 7 |
Read the hex digits from the bottom up: 7, E, A. So 2026 is 0x7EA.
The same method handles the easy cases in one or two steps: 255 divides to 0xFF, and 4095 divides to 0xFFF. And the check value for this method is 61,453, which divides to 0xF00D: 61,453 ÷ 16 leaves 3,840 and remainder 13 (D); 3,840 ÷ 16 leaves 240 and remainder 0; 240 ÷ 16 leaves 15 and remainder 0; 15 ÷ 16 leaves 0 and remainder 15 (F). Read from the bottom: F, 0, 0, D.
I ran every conversion through Python 3.12.3, then checked each result a second time in Node.js. Python’s built-in functions do the same work in one call: hex(2026) returns 0x7ea, and int(‘F00D’, 16) returns 61453. The inputs are chosen by hand: 2026 is the current year and F00D is a classic readable hex word. One run of a deterministic conversion proves the method, and the check that matters is the second runtime agreeing. Two runtimes agreeing matters more than the arithmetic, because the division is deterministic and the independent check is the real evidence. Node.js matched Python on all six values. The division loop is an iteration in programming: divide, record, repeat until the quotient hits zero.
Hex to decimal, worked
The other direction multiplies each digit by 16 raised to its position, counting from the right starting at zero. Add the products, and the sum is the decimal value.
| Digit | Value | Place value | Product |
|---|---|---|---|
| C | 12 | 16^3 = 4096 | 49,152 |
| 0 | 0 | 16^2 = 256 | 0 |
| D | 13 | 16^1 = 16 | 208 |
| E | 14 | 16^0 = 1 | 14 |
| Total | 49,374 |
So 0xC0DE is 49,374. A faster route works left to right: start with the first digit, multiply by 16, add the next digit, and repeat. Run 0xF00D through it and the steps give 15, then 240, then 3,840, then 61,453, the number the division table produced. Both routes agree, and the second one is the check to run when the first feels slow.
The binary shortcut
Hex to binary needs no arithmetic at all, because each hex digit maps to exactly one four-bit group. Swap each digit for its group and the conversion is done.
Take 0xDEAD. D is 1101, E is 1110, A is 1010, and D is 1101 again, so the binary is 1101111010101101, which is 57,005 in decimal. The same swap runs backwards: group binary digits in fours from the right, and each group becomes one hex digit.
hex(57005) = '0xdead'
int('DEAD', 16) = 57005
Can I convert hex to binary without any arithmetic? Yes: each hex digit is one four-bit group, so you just swap digits for groups. The digit table gives every digit’s group, so no division is involved at any step.
The swap works because a hex digit and a nibble are the same thing. How binary code works shows the bit side of that fact. For the full comparison between the two systems, the hexadecimal vs binary page owns the binary-to-hex method. The shortcut is the direction that comes up most.
Where hex shows up?
Hex turns up wherever a person has to read a value a machine produced. Four places cover most of them.
- Color: #FF5733 breaks into three pairs, FF, 57, and 33, which are red 255, green 87, and blue 51. Every color on a web page is three bytes written this way.
- Memory address: 0x7FFE is decimal 32,766, a stack address in the range a debugger prints when a program stops.
- Unicode: U+1F600 is decimal 128,512, the code point of the grinning face emoji. The Unicode code charts list every code point in hex, because the numbers run into six digits in decimal and stay short in hex.
- Network hardware: one IPv6 group runs from 0000 to FFFF, so the largest value in a group is 65,535, the same number as the largest port number. A MAC address is six hex pairs for the same reason: short to read, exact to copy.

The memorable hex words are the ones that stick: F00D and C0DE read like words, and that is why the worked examples in this field keep using them. Assembly listings print addresses and opcodes in hex, so reading one means reading hex. What assembly language is shows those listings in context. And how a compiler works is the other side of the same picture: it turns a hex literal in source code into the machine value it stands for, so the 0x prefix is the first thing a new programmer meets in a listing.
Mistakes that break a conversion
Most hex errors come from five habits, and each one has a plain fix. Work through them once and they stop showing up.
- Reading the remainders top to bottom. The first remainder is the rightmost digit, so read the column from the bottom up.
- Forgetting what the letters are worth. A holds 10, so 0x1A is 26.
- Reading a byte as unsigned when the program treats it as signed. 0xFF means -1 in a signed byte: a signed 8-bit integer runs from -128 to 127, so the top half of the range wraps into negatives.
- Converting a fraction the wrong way round. 0.5 in decimal is 0.8 in hex, because 0.5 times 16 is 8, and the 8 sits in the first place after the point.
- Dropping a leading zero in a fixed-width field. 0x0A and 0xA hold the same value, but a two-digit field expects the zero, and a parser reading fixed widths will misalign without it.
Pick one value from your own screen, a color code in a stylesheet, an address in a log, or a code point in a document, and convert it both ways by hand, then check it with a calculator or one line of code. The first one takes a minute. The second takes seconds.
Frequently Asked Questions About Hexadecimal
What is hexadecimal used for?
It is shorthand for binary wherever a person has to read a machine value: colors on a web page, addresses in a debugger, code points in a character set, and groups in a network address.
How do I convert decimal to hexadecimal?
Divide by 16, write down each remainder, and keep dividing the quotient until it reaches zero. Then read the remainders from the last one to the first.
How do I convert hexadecimal to decimal?
Give each digit its place value, 16 raised to its position from the right, multiply, and add the products together.
What does 0x mean in code?
It marks the number after it as a hex literal, so the compiler reads 0xFF as a value.
Why is hexadecimal base 16?
Because 16 is 2 to the power of 4, so one hex digit fits exactly four bits, and a byte always takes two digits.

Kaleem
Kaleem is a Computer Science graduate (Virtual University of Pakistan) and the founder and editor of Valley AI, where he publishes in-depth, tested guides on computer hardware, artificial intelligence, and how the internet works. Every guide is researched from primary sources, tested hands-on where possible, and updated when the facts change.