Decimal to Hex Converter
Convert a decimal integer into hexadecimal using repeated division by 16.
What the converter returns
Enter a decimal integer and the tool returns the same value written in base 16, using uppercase letters. The default is 255, which becomes FF. That is two hex digits, exactly the width of one byte.
The output has no prefix. It is the numeral alone, so you will usually add 0x yourself when pasting into code, and no padding, so 10 prints as A rather than 0A. Both are conventions applied afterwards rather than part of the conversion.
The formula: divide by sixteen
Each division by 16 leaves a remainder between 0 and 15, and that remainder is one hex digit. The first remainder is the least significant digit and the last is the most significant, so the digits are read in reverse order. Division stops when the quotient reaches zero.
The mechanism is identical to decimal-to-binary, only with 16 instead of 2. That is the whole point of positional notation: changing the base changes the divisor, not the procedure.
Worked example: 255 becomes FF
Divide 255 by 16. The quotient is 15 with remainder 15, which gives the lowest digit F. Divide 15 by 16: quotient 0, remainder 15, which gives the next digit F. The quotient has reached zero, so the answer is FF.
Expand it back to confirm: 15 × 16 + 15 = 240 + 15 = 255. Two digits reach 255, and three reach 4,095, so the digit count tells you the range at a glance. A two-digit hex value always fits in one byte.
The sixteen digits
| Decimal | Hex | Binary | Decimal | Hex | Binary |
|---|---|---|---|---|---|
| 0 | 0 | 0000 | 8 | 8 | 1000 |
| 1 | 1 | 0001 | 9 | 9 | 1001 |
| 2 | 2 | 0010 | 10 | A | 1010 |
| 3 | 3 | 0011 | 11 | B | 1011 |
| 4 | 4 | 0100 | 12 | C | 1100 |
| 5 | 5 | 0101 | 13 | D | 1101 |
| 6 | 6 | 0110 | 14 | E | 1110 |
| 7 | 7 | 0111 | 15 | F | 1111 |
The third and sixth columns are the reason hex exists. Every hex digit covers exactly four bits, so a byte splits into two digits with no waste and no arithmetic: 10101010 is AA, and AA is 170. Reading a hex dump is therefore a matter of recognising sixteen patterns, not of doing division in your head.
- 10 becomes A, the first value that needs a letter
- 16 becomes 10, the first two-digit hex value
- 255 becomes FF, the largest byte
- 256 becomes 100, the first value that overflows a byte
Where the letters start
Values 0 to 9 use the ordinary numerals, and 10 to 15 use A to F because there is no single digit for ten. A value like 165 divides as 10 remainder 5, producing A5, which is why mid-range channel values in a color code contain letters rather than digits.
Where hex appears in practice
Memory addresses are printed in hex because the mapping to bytes is direct, so 0x7FFE1234 tells a debugger more than 2147353140 does. UTF-8 byte sequences are usually listed in hex, with 0xC3 0xA9 for é. Hash digests are long runs of hex, each character worth a nibble. And CSS colors are six hex digits, two per channel.
In each case the benefit is width: hex is four times more compact than binary and aligns to byte boundaries in a way decimal does not. A 32-bit value is eight hex digits or thirty-two binary digits, and the hex form still fits on one line.
Padding to two digits per byte
A byte sequence needs every value written as exactly two digits, so 10 must be 0A and 5 must be 05. Without the pad, the string 0A0B05 becomes A B 5, and the reader can no longer tell where each byte starts. This calculator prints minimum digits, so pad on the left when the output feeds a byte-array format.
Where the conversion bites
- Reading FF as a decimal number: it is 255, not fifteen fifteen
- Forgetting that 0x is a marker, not part of the value
- Losing the pad, so a byte array becomes ambiguous the moment a value drops below 16
- Assuming case matters, when 0xFF and 0xff are the same value
- Crossing the 255 boundary without noticing: 256 needs three digits and no longer fits a byte
The last one causes real bugs. A loop that formats a channel with two digits will silently produce 100 for the value 256, which is four characters wide and shifts everything after it. Range-check before you format, or use a formatter that refuses values above 255.
Range and precision
The input is rounded to a whole number and capped at 1015, well inside the range where JavaScript integers are exact. A million converts to F4240 in five digits, and 4,294,967,295 converts to FFFFFFFF, the largest unsigned 32-bit value.
Hex does not carry a sign or a width by itself. Whether FFFFFFFF means 4,294,967,295 or −1 depends entirely on the type that reads it, which is a property of the program rather than the numeral. When you hand a hex string to another system, state the width and signedness or you have handed over an ambiguous value.
Width also explains the familiar pattern of four-digit and eight-digit hex. A 16-bit register is four digits, so FFFF is its ceiling at 65,535; a 32-bit register is eight digits. When you see a value padded to four digits in a datasheet, that padding is telling you the register size, not decorating the number.
Frequently asked questions
How do I convert 255 to hex?
Divide by 16: 255 gives quotient 15 and remainder 15, then 15 gives quotient 0 and remainder 15. Reading the remainders upward gives FF.
What is 100 in hex?
64. One hundred divided by 16 is 6 remainder 4, so the answer is 64, which expands back to 6×16 + 4 = 100.
Why does hex use A through F?
Base 16 needs sixteen single-character digits. The ten numerals cover 0 to 9 and A to F cover 10 to 15, keeping every position exactly one character wide.
What is 4,294,967,295 in hex?
FFFFFFFF. It is 232 − 1, the largest unsigned 32-bit value, written as eight F digits.
Does case matter in hexadecimal?
No. FF and ff both mean 255, and parsers accept either. This converter prints uppercase because that is the convention in documentation and hex dumps.
Why is my hex output only one digit long?
The tool prints the shortest form, so 10 becomes A rather than 0A. Pad to two characters when the value represents a byte.
What is 1,000,000 in hex?
F4240. That is 15×164 + 4×163 + 2×162 + 4×16, which totals 1,000,000.
Is 256 a valid two-digit hex value?
No. Two digits reach 255, so 256 requires three digits and prints as 100. Anything formatted as a byte must stay at or below 255.
What is 0xFF in decimal?
255. The 0x marks the number as hexadecimal, and FF expands to 15×16 + 15.
Can the converter handle negative numbers?
No, the input starts at 0. Negative values in hex depend on width and representation, for example FFFFFFFF for −1 in 32-bit two’s complement.
Method and sources
- Positional numeral system, base 16.