Decimal to Hex Converter
Going the other way? Convert hex back to decimal →
How do you convert decimal to hex?
Decimal to hex conversion divides the number by 16 over and over, keeping each remainder, then reads the remainders from the last one back to the first.
- Divide the number by 16 and write down the remainder. 156 ÷ 16 leaves 12.
- Divide the quotient by 16 again and keep that remainder too.
- Repeat until the quotient reaches 0.
- Read the remainders from bottom to top: 156 = 9C.
Decimal to Hexadecimal Conversion Table
One hexadecimal digit equals exactly 4 bits (16 = 2⁴); one octal digit equals exactly 3 bits (8 = 2³). Hex and octal are therefore converted by grouping bits, and hex ↔ octal passes through binary. That is the whole method, so the table below is the only thing you need: every group of 4 bits has exactly one hex digit, and the mapping never changes. Binary writes values on the digit set 0, 1 with each place worth 2ⁿ, and a value marked 0b is binary; hex values are marked 0x.
| 4 bits | Hex | Decimal |
|---|---|---|
| 0000 | 0 | 0 |
| 0001 | 1 | 1 |
| 0010 | 2 | 2 |
| 0011 | 3 | 3 |
| 0100 | 4 | 4 |
| 0101 | 5 | 5 |
| 0110 | 6 | 6 |
| 0111 | 7 | 7 |
| 1000 | 8 | 8 |
| 1001 | 9 | 9 |
| 1010 | A | 10 |
| 1011 | B | 11 |
| 1100 | C | 12 |
| 1101 | D | 13 |
| 1110 | E | 14 |
| 1111 | F | 15 |
Each base is defined by three things: which digits it uses, how a value is marked, and what each position is worth.
| Base | Radix | Digits | Prefix | Place worth | Typical range |
|---|---|---|---|---|---|
| Decimal | 10 | 0–9 | none | 10ⁿ | any; decimal pages treat 0–255 as the byte range |
| Hexadecimal | 16 | 0–9, A–F (A=10 … F=15; case-insensitive) | 0x | 16ⁿ | 2 digits cover a byte (00–FF); 6 digits = RGB colour; 8 digits = 32-bit word |
Worked Example: 156 to Hexadecimal
One value, converted the long way so the working is visible. This is the same grid the converter shows when you turn on "show steps".
Result: 156 = 9C
Divide by 16 and keep the remainder, then divide the quotient again, until the quotient reaches 0. For 156 that runs: 156 / 16 = 9 remainder 12; 9 / 16 = 0 remainder 9.
The remainders come out least significant first, so they are read from the bottom of the list back to the top: 9C. Reading them the other way is the single most common error, and it gives a number that looks plausible and is wrong. The check is quick — expand the result back and it must return 156.
Check it in reverse
The value returns unchanged. Convert 9C back and you get 156, because a base change rewrites the digits without touching the quantity they stand for. That is the whole test: if the round trip differs, a digit was misread. To check it by hand, convert the decimal value back to hex and compare it with the number you started from.
Worked examples: decimal to hex
Each example gives the value first, then the working. Click a value to load it in the converter.
What is 255 in hexadecimal?
255 in decimal is FF in hexadecimal.
Method: divide 255 by 16 repeatedly and read the remainders bottom to top.
What is 156 in hexadecimal?
156 in decimal is 9C in hexadecimal.
Method: divide 156 by 16 repeatedly and read the remainders bottom to top.
What is 10 in hexadecimal?
10 in decimal is A in hexadecimal.
Method: divide 10 by 16 repeatedly and read the remainders bottom to top.
What is 100 in hexadecimal?
100 in decimal is 64 in hexadecimal.
Method: divide 100 by 16 repeatedly and read the remainders bottom to top.
What is 8 in hexadecimal?
8 in decimal is 8 in hexadecimal.
Method: divide 8 by 16 repeatedly and read the remainders bottom to top.
What is 16 in hexadecimal?
16 in decimal is 10 in hexadecimal.
Method: divide 16 by 16 repeatedly and read the remainders bottom to top.
What is 32 in hexadecimal?
32 in decimal is 20 in hexadecimal.
Method: divide 32 by 16 repeatedly and read the remainders bottom to top.
What is 64 in hexadecimal?
64 in decimal is 40 in hexadecimal.
Method: divide 64 by 16 repeatedly and read the remainders bottom to top.
What is 128 in hexadecimal?
128 in decimal is 80 in hexadecimal.
Method: divide 128 by 16 repeatedly and read the remainders bottom to top.
What is 12 in hexadecimal?
12 in decimal is C in hexadecimal.
Method: divide 12 by 16 repeatedly and read the remainders bottom to top.
What is 15 in hexadecimal?
15 in decimal is F in hexadecimal.
Method: divide 15 by 16 repeatedly and read the remainders bottom to top.
What is 20 in hexadecimal?
20 in decimal is 14 in hexadecimal.
Method: divide 20 by 16 repeatedly and read the remainders bottom to top.
What is 25 in hexadecimal?
25 in decimal is 19 in hexadecimal.
Method: divide 25 by 16 repeatedly and read the remainders bottom to top.
What is 50 in hexadecimal?
50 in decimal is 32 in hexadecimal.
Method: divide 50 by 16 repeatedly and read the remainders bottom to top.
What is 200 in hexadecimal?
200 in decimal is C8 in hexadecimal.
Method: divide 200 by 16 repeatedly and read the remainders bottom to top.
What is 1000 in hexadecimal?
1000 in decimal is 3E8 in hexadecimal.
Method: divide 1000 by 16 repeatedly and read the remainders bottom to top.
Every example above reverses exactly — expand the same hex digits into a decimal value.
What About Padding, Fractions and Width?
Leading zeros and width
A number carries no leading zeros unless a width is fixed. 9C and 09C are the same value, so the converter writes the short form. Fixed widths belong to bytes and registers, not to arithmetic. how any base converts to any other covers where width does matter.
Fractions and the point
Digits after a point convert by the same rule with negative powers, so the first place after the point is worth 1/16. Many fractions that end neatly in decimal repeat forever in binary, which is where rounding creeps in.
Negative values
A minus sign is kept in front of the digits. Fixed-width binary encodes sign differently, using two's complement, and that is a separate rule from the base change itself.
How large a value can be
The method has no ceiling; each extra decimal digit multiplies the range by 10. Practical limits come from the width a machine stores the value in, not from the conversion.
Decimal to Hex in Code
The same rule in one line. Both divide repeatedly and return the digits in order.
Python: format(156, 'X') JavaScript: (156).toString(16).toUpperCase() Common Mistakes
- Reading the remainders top to bottom. They come out in reverse, so the digits land backwards.
- Using a digit the base does not have — an 8 in octal, or a 2 in binary. The value cannot be read at all.
- Grouping bits from the left. Groups are counted from the right, and the leftmost group is the one that gets padded.
- Treating the result as a character code. 65 is a number here, not the letter A.
Frequently Asked Questions
What do you do when a remainder is 10 to 15?
Write it as a hex digit, from the set 0–9, A–F (A=10 … F=15; case-insensitive). Dividing 156 by 16 leaves quotient 9 and remainder 12, so the digits are 9 and C, and 156 in hex is 9C.
Why are colour codes written in hex?
Because one byte runs 0 to 255 and fits in exactly two hex digits, so three colour channels pack into six. 0b marks binary, 0o octal, 0x hexadecimal; a leading # marks a hex colour. Hexadecimal is not case-sensitive (FF = ff); iToolHub writes hex digits in uppercase.
How do you convert decimal to hex in Python?
Format the number in base 16: format(156, 'X') returns 9C. A lowercase x returns 9c instead, and hex(156) adds the 0x prefix; the one-liner under Decimal to Hex in Code uses uppercase.
The quantity never changes, only the digits, so the same value converts straight back in the hex to decimal direction.
Related Conversions
The rest of the family sits on the converter grid for every pair.