Decimal to HEX: Convert Base 10 into Base 16
Decimal and hexadecimal are positional number systems. Decimal, or base 10, uses ten digits from 0 to 9. Hexadecimal, often written as HEX, uses sixteen symbols: 0–9 and A–F. Each hexadecimal position represents a power of 16. The SnapZain decimal to hex converter changes a non-negative decimal whole number into its base-16 representation. This decimal to hex conversion keeps the numeric value the same while writing it with hexadecimal digits.
For example, decimal 45 is hexadecimal 2D. Divide 45 by 16 to get quotient 2 and remainder 13; hexadecimal D represents 13. Reading the quotient followed by the remainder gives 2D. Enter a single number or space-separated values in the calculator above to perform the same conversion.
How to Convert Decimal to Hex by Repeated Division
The repeated-division method works for any non-negative whole number. Since hexadecimal is base 16, divide by 16 rather than 2 or 10. The remainders form the hexadecimal digits, starting at the rightmost position.
- Divide the decimal number by 16. Keep the whole-number quotient and remainder.
- Convert the remainder to a hex digit. Remainders 0–9 stay as digits; 10–15 become A–F.
- Divide the quotient by 16 again. Record the next remainder.
- Stop when the quotient is zero. Reverse the list of remainders to write the hexadecimal result.
For 45, the first division gives 45 ÷ 16 = 2 remainder 13. The quotient 2 is now less than 16, so it becomes the leading digit. Remainder 13 maps to D. Therefore, 45₁₀ = 2D₁₆. For larger values, continue dividing the quotient until it reaches zero, then read all recorded remainders in reverse order.
“Hexadecimal conversion is repeated division by 16; the only extra step is writing remainders 10–15 as A–F.”
The Decimal to Hex Formula
Each hexadecimal digit is multiplied by a power of 16 according to its position. The rightmost position is 16⁰, the next is 16¹, then 16², and so on. If a number has digits hₙ through h₀, its decimal value is:
hₙ × 16ⁿ + … + h₂ × 16² + h₁ × 16¹ + h₀ × 16⁰
For 2D, D has decimal value 13. Calculate 2 × 16¹ + 13 × 16⁰ = 32 + 13 = 45. This place-value formula converts hexadecimal to decimal and is a reliable way to check a decimal-to-hex result in the opposite direction.
| Decimal remainder | Hex digit | Decimal remainder | Hex digit |
|---|---|---|---|
| 0 | 0 | 8 | 8 |
| 1 | 1 | 9 | 9 |
| 2 | 2 | 10 | A |
| 3 | 3 | 11 | B |
| 4 | 4 | 12 | C |
| 5 | 5 | 13 | D |
| 6 | 6 | 14 | E |
| 7 | 7 | 15 | F |
The A–F mapping is essential: a remainder of 12 is C, not the two-character text “12.” This is why a conversion routine must replace each remainder above 9 with its single hexadecimal digit.
Decimal to Hex Table and Worked Examples
A small lookup table makes familiar values easier to recognize. Decimal values below 16 use a single hex digit. Decimal 16 is written as 10 in hex because it is one group of sixteen and zero ones.
| Decimal | Hexadecimal | Check |
|---|---|---|
| 0 | 0 | Zero in either base |
| 10 | A | A represents decimal 10 |
| 15 | F | F represents decimal 15 |
| 16 | 10 | 1 × 16 + 0 |
| 20 | 14 | 1 × 16 + 4 |
| 26 | 1A | 1 × 16 + 10 |
| 45 | 2D | 2 × 16 + 13 |
| 255 | FF | 15 × 16 + 15 |
| 256 | 100 | 1 × 16² |
20 decimal to hex
Divide 20 by 16: the quotient is 1 and the remainder is 4. Both are valid hexadecimal digits, so 20₁₀ = 14₁₆. Confirm with place values: 1 × 16 + 4 = 20.
Convert 255 from decimal to hex
255 divided by 16 gives quotient 15 and remainder 15. Decimal 15 is F in hexadecimal, so both digits are F: 255₁₀ = FF₁₆.
Convert 256 from decimal to hex
256 is exactly 16². In base 16, that is a 1 in the 16² place followed by two zeroes: 256₁₀ = 100₁₆.
Using the Online Decimal to HEX Converter
This decimal to hex calculator applies the same repeated-division rule and returns uppercase letters for hexadecimal digits. To convert decimal to hex, enter one non-negative whole number and select Convert. For a batch, separate the values with spaces, for example 20 45 255; the output will be 14 2D FF.
- Use decimal digits 0 through 9 for each input number.
- Separate multiple whole numbers with spaces; commas are not valid separators.
- Fractions, negative values, and mixed text are not accepted.
- The input field allows up to 500 characters.
- Each number must be at most 9007199254740991 so JavaScript can represent it exactly.
- Use Copy to clipboard for the result, Clear to reset, or Ctrl + Enter to convert from the input field.
The limit is about numeric precision, not the number of hex digits a person might write by hand. JavaScript’s ordinary number type exactly represents all integer values through 2⁵³ − 1. Values above that bound can be rounded, so the converter refuses them rather than claim an inaccurate conversion.
Decimal to Hex in C
C’s formatted output functions can display an integer in hexadecimal without manually dividing it. The %X format specifier prints uppercase A–F, while %x prints lowercase letters. Choose a type large enough for the values your program needs to represent.
#include <stdio.h>
int main(void) {
unsigned int value = 20;
printf("%X\n", value); /* prints 14 */
return 0;
}
This illustrates decimal to hex C code for a small unsigned integer. The C language’s integer type ranges depend on the implementation, so check the type limits when handling larger values. The web converter has a separate documented limit of 9007199254740991.
Binary, Decimal, and Hexadecimal Conversion
Binary, decimal, and hexadecimal can all describe the same integer. Hexadecimal is compact because one hex digit corresponds to four binary bits. For instance, hex D is binary 1101. If your task is binary to decimal to hex, first read the binary value as a number and then express it in base 16; alternatively, group the binary digits into four-bit blocks and map each block directly to a hex digit.
For a decimal to hex to binary workflow, convert decimal to hexadecimal and replace each hex digit with four bits. Decimal 45 becomes hex 2D; 2 maps to 0010 and D maps to 1101, resulting in 00101101. Dropping leading zeros gives the minimal binary form 101101. Pick the route that makes each source and destination clear.
Related tools: Binary to Text interprets binary groups as characters; HEX to Decimal converts base 16 back to base 10; Binary to Decimal converts base 2 to base 10; and Decimal to Binary converts base 10 to base 2. Each converter has a distinct direction and purpose.
“A base conversion changes the digits used to write a value; it does not change the value itself.”
Conclusion: Convert Decimal Values in Base 16
To convert decimal to hex, divide the non-negative whole number by 16, translate remainders 10–15 into A–F, and read the digits in reverse order. Check the result with powers of 16 or convert it back to decimal. SnapZain’s converter handles one value or space-separated batches, returns uppercase hexadecimal, and enforces a 500-character input limit and a maximum exact integer of 9007199254740991.