What is decimal to hexadecimal conversion?
Decimal to hexadecimal (hex) conversion changes a number from base 10 to base 16. The core step is repeated division by 16: each remainder becomes one hex digit, and the digits read from the last remainder to the first. Base 10 uses ten digits (0–9). Base 16 uses sixteen: 0–9 and A–F, where A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
Decimal 345 becomes hex 159 in three divisions: 345 ÷ 16 = 21 remainder 9, 21 ÷ 16 = 1 remainder 5, and 1 ÷ 16 = 0 remainder 1. Read upward, the remainders give 159.
Each hex digit maps to exactly 4 bits, so two hex digits always make one byte (8 bits). That direct mapping makes hex the standard notation for memory addresses, colour values and machine-level data.
Decimal number system (base 10)
The decimal system uses ten digits, 0 through 9, and each position is worth ten times the position to its right. The number 653 breaks down as 6×10² + 5×10¹ + 3×10⁰ = 600 + 50 + 3.
People count, measure and price in decimal, so most software shows numbers in base 10 even when it stores them in binary (base 2). Type another number in the visual to see how each digit adds its share.
Hexadecimal number system (base 16)
The hexadecimal system uses sixteen digits: 0–9 for the values 0 to 9 and A–F for 10 to 15. Each position is worth sixteen times the position to its right, so hex 62C = 6×16² + 2×16¹ + C×16⁰ = 1,536 + 32 + 12 = 1,580 in decimal.
Hex appears in four common notations:
- 0x prefix: 0xFF in C, Python, JavaScript and Java.
- # prefix: #FF0000 in HTML and CSS colour codes.
- h suffix: FFh in assembly language and Intel documents.
- No marker: FF in casual writing and in this converter.
Pick a notation to see the same number written each way.
Benefits of understanding decimal to hex conversion
Decimal to hex conversion gives four practical advantages in computing and development:
- Compact representation. One hex digit holds 4 bits, so a 32-bit value takes 8 hex digits instead of up to 10 decimal digits. FFFFFFFF is easier to scan than 4,294,967,295.
- Memory addressing. Debuggers, crash logs and operating systems show addresses in hex. The address 0x7FFE5A10 names a byte position in memory.
- Colour coding. Web colours use six hex digits split into three channels: #1E90FF means red 1E (30), green 90 (144) and blue FF (255).
- Debugging and error codes. System error codes, registry values and protocol headers use hex. Reading the Windows stop code 0x0000007E takes decimal-to-hex fluency.
Methods for converting decimal to hex
Two methods cover every case: the division method for any number, and the lookup table for quick single-digit results.
Division method (repeated division by 16)
The division method works for any positive whole number, however large.
- Divide the decimal number by 16. Record the quotient and the remainder.
- Write the remainder as the rightmost hex digit. Map 10 to A, 11 to B, 12 to C, 13 to D, 14 to E and 15 to F.
- Divide the quotient by 16. Record the new quotient and remainder.
- Repeat until the quotient reaches 0.
- Read the hex digits from the last remainder to the first.
Lookup table method
The lookup table maps each value from 0 to 15 to its single hex digit. For larger numbers, divide by 16 and look up each quotient and remainder in the table instead of converting it in your head. Drag the slider to split any byte value into its two digits.
| Decimal | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| Hex | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F |
The division method handles numbers of any size with one consistent process. The lookup table speeds up each step by removing the mental conversion from remainder to letter.
How to convert decimal to hex
Decimal to hex conversion examples
Example 1: convert 7,562 to hex
| Step | Division | Quotient | Remainder | Hex digit |
|---|---|---|---|---|
| 1 | 7,562 ÷ 16 | 472 | 10 | A |
| 2 | 472 ÷ 16 | 29 | 8 | 8 |
| 3 | 29 ÷ 16 | 1 | 13 | D |
| 4 | 1 ÷ 16 | 0 | 1 | 1 |
Read the hex digits from the last step to the first: 7,562 = 1D8A. Check: 1×4,096 + 13×256 + 8×16 + 10×1 = 4,096 + 3,328 + 128 + 10 = 7,562.
Example 2: convert 255 to hex
- 255 ÷ 16 = 15 remainder 15, which is F.
- 15 ÷ 16 = 0 remainder 15, which is F.
Read upward: 255 = FF. This is the largest value one byte can hold. It appears in colour codes (#FFFFFF is white), subnet masks (255.255.255.0) and maximum unsigned 8-bit values. Try both examples in the visual, then drag the step slider to replay them.
How to convert decimal fractions to hex
To convert the fractional part, multiply the fraction by 16 and take the whole part as the next hex digit after the point. Repeat with the remaining fraction until it reaches 0 or you have enough precision. Convert the whole part and the fraction separately, then combine them.
For 12.75, the whole part 12 is C. The fraction gives 0.75 × 16 = 12.0, which is C, and nothing remains. So 12.75 = C.C.
Some decimal fractions repeat in hex. The fraction 0.1 gives 0.1999… because 0.1 × 16 = 1.6, then 0.6 × 16 = 9.6, and the 9.6 step repeats. The converter above stops after 16 hex places and marks the result as rounded.
Negative numbers: two’s complement
Computers store negative whole numbers in two’s complement with a fixed bit width of 8, 16, 32 or 64. To find the hex form of a negative number, add 2ⁿ to it, where n is the bit width.
For −1 in 8 bits: −1 + 2⁸ = −1 + 256 = 255 = FF. For −1,000 in 16 bits: −1,000 + 2¹⁶ = 64,536 = FC18.
| Decimal | 8-bit hex | 16-bit hex | 32-bit hex |
|---|---|---|---|
| −1 | FF | FFFF | FFFFFFFF |
| −100 | 9C | FF9C | FFFFFF9C |
| −128 | 80 | FF80 | FFFFFF80 |
| −1,000 | does not fit | FC18 | FFFFFC18 |
The converter above accepts a minus sign and shows the plain negative hex value. For two’s complement at a set bit width, use the signed hex to decimal converter.
Decimal to hexadecimal conversion table
Common values sit in the table below. The grid shows every byte from 0 to 255: the row gives the left hex digit and the column gives the right one. Tap or hover over a cell to read its decimal and hex values.
| Decimal | Hex |
|---|---|
| 0 | 0 |
| 1 | 1 |
| 2 | 2 |
| 4 | 4 |
| 8 | 8 |
| 10 | A |
| 15 | F |
| 16 | 10 |
| 20 | 14 |
| Decimal | Hex |
|---|---|
| 32 | 20 |
| 48 | 30 |
| 50 | 32 |
| 64 | 40 |
| 80 | 50 |
| 90 | 5A |
| 100 | 64 |
| 127 | 7F |
| Decimal | Hex |
|---|---|
| 128 | 80 |
| 192 | C0 |
| 200 | C8 |
| 255 | FF |
| 256 | 100 |
| 500 | 1F4 |
| 512 | 200 |
| 1,000 | 3E8 |
| 1,024 | 400 |
For the full 00–FF byte table with binary values, see the hex to decimal table.
Decimal to hex example problems
Practice problems
Solve these by hand, then check each answer with the converter above or with the quiz below.
- Convert 49 to hex.
- Convert 1,228 to hex.
- Convert 600 to hex.
- Convert 192 to hex.
- Convert 10,000 to hex.
- Convert 0.5 to hex.
Answers:
- 49 = 31 (49 ÷ 16 = 3 remainder 1).
- 1,228 = 4CC (1,228 ÷ 16 = 76 remainder 12; 76 ÷ 16 = 4 remainder 12; 4 ÷ 16 = 0 remainder 4).
- 600 = 258 (600 ÷ 16 = 37 remainder 8; 37 ÷ 16 = 2 remainder 5; 2 ÷ 16 = 0 remainder 2).
- 192 = C0 (192 ÷ 16 = 12 remainder 0; 12 ÷ 16 = 0 remainder 12).
- 10,000 = 2710 (10,000 ÷ 16 = 625 remainder 0; 625 ÷ 16 = 39 remainder 1; 39 ÷ 16 = 2 remainder 7; 2 ÷ 16 = 0 remainder 2).
- 0.5 = 0.8 (0.5 × 16 = 8.0).
Decimal to hex in programming
Most languages convert decimal to hex with one built-in function or format specifier. Pick a language in the visual to see the call and what it prints for your number.
Decimal to hex in Python
Python’s built-in hex() returns the hex string with a 0x prefix. The format() function gives more control over case and padding.
hex(255) # '0xff'
hex(2024) # '0x7e8'
format(255, 'X') # 'FF' (upper case, no prefix)
format(255, '04X') # '00FF' (zero-padded to 4 digits)
f'{2024:#x}' # '0x7e8'For the full guide with error handling and large numbers, see hex to decimal in Python.
Decimal to hex in C
C uses printf() with the %x (lower case) or %X (upper case) format specifier. The sprintf() function stores the result in a string buffer.
#include <stdio.h>
int main(void) {
int n = 255;
printf("%x\n", n); // ff
printf("%X\n", n); // FF
printf("%04X\n", n); // 00FF (zero-padded)
char buf[10];
sprintf(buf, "%X", n);
// buf now holds "FF"
return 0;
}For unsigned values and edge cases, see hex to decimal in C.
Other languages
| Language | Function | Example | Result |
|---|---|---|---|
| JavaScript | .toString(16) | (255).toString(16) | "ff" |
| Java | Integer.toHexString() | Integer.toHexString(255) | "ff" |
| Excel | =DEC2HEX() | =DEC2HEX(255) | "FF" |
| Bash | printf '%x' | printf '%x' 255 | ff |
Each language has its own guide on this site: JavaScript, Java, Excel and Linux and Bash.
Frequently asked questions about decimal to hex conversion
How do you convert decimal to hexadecimal?
Why is hexadecimal used in computing?
What is the hex equivalent of decimal 14?
What is decimal 192 in hex?
What does 0 mean in hex?
What are common misconceptions about decimal to hex conversion?
In decimal to hex conversion, what changes between the bases?
Can I convert decimal fractions to hex?
Does a negative decimal number have a hex form?
Related tools
- Hex to decimal converter: convert hex back to decimal with digit-by-digit steps.
- Hex to binary converter: convert between hex, decimal and binary.
- Hex to octal converter: convert hex to octal (base 8).
- Signed hex to decimal: convert two’s complement hex values.
- Bulk hex to decimal: convert a list of values at once.
- Hex to decimal table: the full 0–FF reference chart.