Hex to Decimal

Decimal to hex converter

Type a decimal number to see its hex value and every division step. The sections below cover the method, worked examples, fractions, negative numbers, a reference table, practice questions and code in six languages.

Hex

Divide by 16, keep the remainder read the hex digits from the bottom up

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:

  1. 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.
  2. Memory addressing. Debuggers, crash logs and operating systems show addresses in hex. The address 0x7FFE5A10 names a byte position in memory.
  3. Colour coding. Web colours use six hex digits split into three channels: #1E90FF means red 1E (30), green 90 (144) and blue FF (255).
  4. 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.

  1. Divide the decimal number by 16. Record the quotient and the remainder.
  2. 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.
  3. Divide the quotient by 16. Record the new quotient and remainder.
  4. Repeat until the quotient reaches 0.
  5. 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.

Decimal0123456789101112131415
Hex0123456789ABCDEF

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

StepDivisionQuotientRemainderHex digit
17,562 ÷ 1647210A
2472 ÷ 162988
329 ÷ 16113D
41 ÷ 16011

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.

Decimal8-bit hex16-bit hex32-bit hex
−1FFFFFFFFFFFFFF
−1009CFF9CFFFFFF9C
−12880FF80FFFFFF80
−1,000does not fitFC18FFFFFC18

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.

DecimalHex
00
11
22
44
88
10A
15F
1610
2014
DecimalHex
3220
4830
5032
6440
8050
905A
10064
1277F
DecimalHex
12880
192C0
200C8
255FF
256100
5001F4
512200
1,0003E8
1,024400

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.

  1. Convert 49 to hex.
  2. Convert 1,228 to hex.
  3. Convert 600 to hex.
  4. Convert 192 to hex.
  5. Convert 10,000 to hex.
  6. Convert 0.5 to hex.

Answers:

  1. 49 = 31 (49 ÷ 16 = 3 remainder 1).
  2. 1,228 = 4CC (1,228 ÷ 16 = 76 remainder 12; 76 ÷ 16 = 4 remainder 12; 4 ÷ 16 = 0 remainder 4).
  3. 600 = 258 (600 ÷ 16 = 37 remainder 8; 37 ÷ 16 = 2 remainder 5; 2 ÷ 16 = 0 remainder 2).
  4. 192 = C0 (192 ÷ 16 = 12 remainder 0; 12 ÷ 16 = 0 remainder 12).
  5. 10,000 = 2710 (10,000 ÷ 16 = 625 remainder 0; 625 ÷ 16 = 39 remainder 1; 39 ÷ 16 = 2 remainder 7; 2 ÷ 16 = 0 remainder 2).
  6. 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

LanguageFunctionExampleResult
JavaScript.toString(16)(255).toString(16)"ff"
JavaInteger.toHexString()Integer.toHexString(255)"ff"
Excel=DEC2HEX()=DEC2HEX(255)"FF"
Bashprintf '%x'printf '%x' 255ff

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?
Divide the decimal number by 16, record the remainder as a hex digit, and repeat with the quotient until it reaches 0. Read the remainders from last to first. Map the remainders 10 to 15 to the letters A to F.
Why is hexadecimal used in computing?
Hex packs 4 bits into one digit, so it shows binary data in fewer characters than decimal or binary. A 32-bit memory address takes 8 hex digits against up to 10 decimal digits. Programmers use hex for memory addresses, colour codes (#FFFFFF), error codes and packet headers.
What is the hex equivalent of decimal 14?
Decimal 14 equals hex E. The letters A to F stand for 10 to 15, so E maps to 14.
What is decimal 192 in hex?
Decimal 192 equals hex C0. 192 ÷ 16 = 12 remainder 0, and 12 ÷ 16 = 0 remainder 12 (C). Read upward: C0. The value 192 starts the common private network address 192.168.x.x.
What does 0 mean in hex?
Hex 0 equals decimal 0. Both systems use the same symbol for zero.
What are common misconceptions about decimal to hex conversion?
Three misconceptions cause most confusion. “Hex is only for programmers.” Network engineers read hex in MAC addresses and IPv6, and designers use hex colour codes daily. “The conversion is hard.” It has one operation, division by 16, repeated until the quotient is 0. “The letters A to F are special.” They are ordinary digits that extend the count past 9: A is 10, B is 11, and so on up to F = 15.
In decimal to hex conversion, what changes between the bases?
The base changes from 10 to 16, which changes how each digit position adds to the total. In decimal, positions multiply by powers of 10 (1, 10, 100, 1,000). In hex, they multiply by powers of 16 (1, 16, 256, 4,096). The value stays the same. Only the notation changes.
Can I convert decimal fractions to hex?
Yes. Multiply the fractional part by 16 repeatedly and take the whole part of each product as the next hex digit. For example, 0.75 × 16 = 12.0, so 0.75 = 0.C in hex. Some fractions, such as 0.1, repeat.
Does a negative decimal number have a hex form?
Yes. Computers store negatives in two’s complement at a fixed bit width. Decimal −1 is FF in 8 bits, FFFF in 16 bits and FFFFFFFF in 32 bits. The signed converter works with these values.