Decimal to Hex Converter
Decimal to hex converter: enter an integer and read it in hexadecimal. 755 becomes 2F3 by repeated division by 16, and the steps are listed. Negative numbers show their two's complement form. Lists of numbers convert line by line, in your browser.
| Divide | Quotient | Remainder | Hex digit |
|---|---|---|---|
| 755 | 47 | 3 | 3 |
| 47 | 2 | 15 | F |
| 2 | 0 | 2 | 2 |
How to convert decimal to hexadecimal by repeated division
To write a whole number in base 16, divide it by 16 and note the remainder. Divide the quotient by 16 and note that remainder. Keep going until the quotient is 0. The remainders, read from the last to the first, are the hex digits, with 10 to 15 written as A to F. Each remainder is the count of ones left over at that position, which is why the first remainder is the last digit of the answer.
The diagram works the example 755. 755 ÷ 16 is 47 with 3 left over, 47 ÷ 16 is 2 with 15 left over (F), and 2 ÷ 16 is 0 with 2 left over. Read bottom to top: 2, F, 3.
The tables below do the same for two numbers people ask about. 1,000 gives 3E8 because the middle remainder is 14, which is E. 65,535 gives FFFF because every remainder is 15.
| Divide | Quotient | Remainder | Hex digit |
|---|---|---|---|
| 1,000 | 62 | 8 | 8 |
| 62 | 3 | 14 | E |
| 3 | 0 | 3 | 3 |
| Divide | Quotient | Remainder | Hex digit |
|---|---|---|---|
| 65,535 | 4,095 | 15 | F |
| 4,095 | 255 | 15 | F |
| 255 | 15 | 15 | F |
| 15 | 0 | 15 | F |
The other method: take away the largest power of 16
Division is mechanical and works for any size, but a second method is quicker for numbers you can see the scale of. Find the largest power of 16 that fits (1, 16, 256, 4,096, 65,536, and so on). Count how many times it fits; that count is the first digit. Subtract and repeat with the next lower power.
For 755: 256 fits twice (512), leaving 243. 16 fits fifteen times (240), leaving 3. So the digits are 2, 15 and 3, which is 2F3. The method makes the size of the answer obvious from the start, since 755 lies between 256 and 4,096 and must therefore have three hex digits. A number needs one hex digit below 16, two below 256, three below 4,096, four below 65,536.
Decimal to hex answers people look up
Round numbers in decimal are rarely round in hex, and the reverse is just as true. The list below is generated by the converter, so it can be used as a reference. Powers of two stand out in hex (256 is 100, 4,096 is 1000), whereas powers of ten do not (1,000 is 3E8, 1,000,000 is F4240).
| Decimal | Hexadecimal | Where you meet it |
|---|---|---|
| 10 | A | First value that needs a letter: A |
| 15 | F | Largest single hex digit |
| 16 | 10 | First two-digit hex number, 10 |
| 32 | 20 | ASCII space (0x20) |
| 64 | 40 | ASCII at sign (0x40) |
| 100 | 64 | Ordinary round number, not round in hex |
| 127 | 7F | Largest signed 8-bit value; ASCII DEL |
| 128 | 80 | Smallest unsigned value with the top bit set |
| 255 | FF | Largest byte value |
| 256 | 100 | One past the byte range |
| 1,000 | 3E8 | A thousand |
| 1,024 | 400 | A kibibyte |
| 4,095 | FFF | Largest 12-bit value |
| 4,096 | 1000 | A common memory page size |
| 65,535 | FFFF | Largest 16-bit value; highest port number |
| 65,536 | 10000 | Number of 16-bit values |
| 1,000,000 | F4240 | A million |
A parity check catches many slips. Sixteen is even, so a decimal number is even exactly when its last hex digit is even: 755 is odd and ends in 3, 1,000 is even and ends in 8. If the last digit of your answer disagrees with the parity of the original, a remainder was miscalculated.
For the reverse direction, the hex to decimal converter does the same job with the by-hand method laid out.
Negative numbers: two's complement in hex
Hex has no minus sign inside a fixed-width integer. Computers store negative numbers in two's complement, which means the stored pattern for −x in n bits is 2^n − x. For −1 in 8 bits that is 256 − 1 = 255, so FF. The same −1 in 16 bits is 65,536 − 1 = 65,535, FFFF, and in 32 bits it is FFFFFFFF. The width has to be chosen before the answer exists, because the leading digits are filled with F to keep the sign.
The converter keeps the minus sign on the hex result (−255 is −FF) and also tells you the smallest width that can hold the value and the stored form. The table shows the stored form for several negative numbers.
| Decimal | Smallest width | Stored as |
|---|---|---|
| −1 | 8 bits | FF |
| −2 | 8 bits | FE |
| −128 | 8 bits | 80 |
| −129 | 16 bits | FF7F |
| −255 | 16 bits | FF01 |
| −32,768 | 16 bits | 8000 |
| −2,147,483,648 | 32 bits | 80000000 |
−128 fits in 8 bits as 80, but −129 does not, so it moves up to 16 bits and becomes FF7F. A quick check: in two's complement the stored value of a negative number always starts with a hex digit of 8 to F, because the top bit is set.
Two other ways of storing negatives exist and are worth recognizing. Sign-magnitude keeps the sign in the top bit and the absolute value in the rest, so −5 in 8 bits is 85; it appears in floating-point formats and some older machines. One's complement inverts every bit, so −5 is FA; the checksum in IP and TCP headers is still computed this way. Everything on this page uses two's complement, which is what current processors and programming languages use for integers.
Converting large numbers and the 64-bit limit
The repeated-division method needs no upper limit, but the tool you use might. Most programming languages store integers in 64 bits, so the largest unsigned value is 18,446,744,073,709,551,615 (FFFFFFFFFFFFFFFF) and the largest signed one is 9,223,372,036,854,775,807 (7FFFFFFFFFFFFFFF). JavaScript numbers are 64-bit floating-point values, which store integers exactly only up to 9,007,199,254,740,991. Past that, neighbouring integers collapse: 9007199254740993 is displayed as 9007199254740992 before any hex conversion even happens.
This converter reads the input as an arbitrary-precision integer, so a 40-digit decimal number converts without rounding. Cryptographic keys and hashes, which are numbers of 128 to 4,096 bits, are routinely written this way. If you have the number as a string, paste it; if it came from a spreadsheet, check that the cell format is text, because a spreadsheet keeps about 15 significant digits.
Decimal fractions in hex
A fractional part is converted by multiplying by 16 and taking the whole part of the product as the next digit. 0.75 × 16 = 12, which is C, and nothing is left, so 0.75 is 0.C in hex. 0.5 × 16 = 8, so 0.5 is 0.8. A fraction terminates in hex exactly when its denominator is a power of two, which excludes 0.1: 0.1 × 16 = 1.6, then 0.6 × 16 = 9.6, then 0.6 again, and the digit 9 repeats forever. In JavaScript, (0.1).toString(16) prints 0.1999999999999a, the stored approximation, and the final a is a rounding artefact.
The converter on this page handles whole numbers. Floating-point values, where the same fraction problem appears inside the exponent and mantissa fields, are the subject of a separate pair of converters, float to hex and hex to float.
Leading zeros, fixed width and the 0x prefix
A number has no leading zeros, but a field often does. A byte is always two hex digits (0A, not A), a 16-bit value four, a 32-bit value eight and a 64-bit value sixteen. Colors written for CSS have six digits, so the number 255 as a color channel is FF but the value 10 is 0A, and dropping the zero turns a valid color into a different one. The converter outputs the shortest form and you pad it to the field width: 0x007F, 0x0000007F.
The 0x prefix says that what follows is hex. It is required in C, C++, Java, JavaScript and Python source, and optional in most data formats. Other conventions exist (a trailing h in assembly, a leading $ in Pascal, # in CSS) and are covered on the hexadecimal reference page. Both prefix and upper-case output can be switched on in the options row.
Decimal to hex in Python, JavaScript, C and the shell
hex(755) # '0x2f3'
format(755, "X") # '2F3'
f"{755:04X}" # '02F3' (padded to four digits)
hex(-255 & 0xFFFF) # '0xff01' (two's complement in 16 bits)(755).toString(16) // '2f3'
(755).toString(16).toUpperCase() // '2F3'
(-255 >>> 0).toString(16) // 'ffffff01' (32-bit two's complement)
BigInt("18446744073709551615").toString(16) // 'ffffffffffffffff'printf("%X\n", 755); /* 2F3 */
printf("%04X\n", 755); /* 02F3 */
printf("%llX\n", 18446744073709551615ULL); /* FFFFFFFFFFFFFFFF */printf '%X\n' 755 # 2F3
[Convert]::ToString(755, 16) # 2f3
"{0:X}" -f 755 # 2F3(-255).toString(16) gives −ff, a minus sign followed by the magnitude, and not the stored form. That is the same output as this converter's main result; use the unsigned right shift above, or the two's complement line in the results, when you need the bytes that would actually be stored.
Where you need to convert decimal to hex
Color channels in design tools are decimal (0 to 255) and CSS wants hex: the channels 255, 136 and 0 become FF, 88 and 00, so the color is #FF8800. Ports are decimal in configuration files and hex in packet captures: 8080 is 1F90. An IPv4 address is four decimal numbers that are really four bytes, so 192.168.0.1 is C0 A8 00 01, or C0A80001 as a single value. Unicode code points are quoted in hex (U+00E9) although many references list the decimal number (233).
When the decimal number is a character code, ASCII to hex does the lookup for whole strings. Converting several numbers at once is a matter of pasting them on separate lines, which also works for the lists of RGB channels or bytes you copy from a table.
Three worked examples from start to finish
The year 2026 is a good small case. 2026 ÷ 16 is 126 with 10 left over, so the last digit is A. 126 ÷ 16 is 7 with 14 left over, so the next digit is E. 7 ÷ 16 is 0 with 7 left over, so the first digit is 7. Reading the remainders from the last to the first gives 7EA. Check it the other way: 7 × 256 = 1,792, plus 14 × 16 = 224, plus 10, which is 2,026.
A number whose hex form is a word makes a more interesting test. 48,879 ÷ 16 is 3,054 with 15 left over (F). 3,054 ÷ 16 is 190 with 14 left over (E). 190 ÷ 16 is 11 with 14 left over (E). 11 ÷ 16 is 0 with 11 left over (B). The remainders read upward are B, E, E, F, so 48,879 is BEEF. Notice that every remainder above 9 is written as a single letter; writing 14 as the two characters 1 and 4 is the commonest slip when doing this on paper.
One million shows what a round decimal number looks like in hex. 1,000,000 ÷ 16 is 62,500 with 0 left over. 62,500 ÷ 16 is 3,906 with 4 left over. 3,906 ÷ 16 is 244 with 2 left over. 244 ÷ 16 is 15 with 4 left over. 15 ÷ 16 is 0 with 15 left over. Reading upward: F, 4, 2, 4, 0, which is F4240. The trailing zero is real: 1,000,000 is divisible by 16, so its last hex digit is 0.
How many hex digits a decimal number needs
The number of hex digits grows by one each time the value passes a power of 16. A value below 16 needs one digit, below 256 two, below 4,096 three. Knowing the thresholds lets you size a field or catch a mistake: if you converted a number of about four million and got seven digits, something is wrong, because four million is below 16^6 = 16,777,216 and needs six.
| Hex digits | Largest value | Same in hex | Common name |
|---|---|---|---|
| 1 | 15 | F | One nibble |
| 2 | 255 | FF | One byte |
| 3 | 4,095 | FFF | 12 bits, a 4 KiB page offset |
| 4 | 65,535 | FFFF | 16 bits, a word |
| 6 | 16,777,215 | FFFFFF | 24 bits, a six-digit CSS color |
| 8 | 4,294,967,295 | FFFFFFFF | 32 bits, a double word |
| 16 | 18,446,744,073,709,551,615 | FFFFFFFFFFFFFFFF | 64 bits, a quad word |
Decimal to hex for colors, opacity and alpha
Design tools show colors as three decimal channels from 0 to 255, and CSS wants hex. Convert each channel on its own and join the three pairs, keeping a leading zero where the hex has one digit. The channels 11, 94 and 107 become 0B, 5E and 6B, so the color is #0B5E6B. Dropping the zero from 0B would leave five digits, which is not a valid color.
Opacity is the part that trips people up. Eight-digit CSS colors and many graphics formats add a fourth pair, the alpha channel, which runs from 00 (fully transparent) to FF (fully opaque). A percentage has to be scaled by 255 and rounded before it is converted: 50% is 127.5, which rounds to 128, hex 80. The table gives the values for the usual steps. The reverse direction for whole colors is hex to RGB.
| Opacity | Decimal (0-255) | Alpha hex |
|---|---|---|
| 100% | 255 | FF |
| 90% | 230 | E6 |
| 80% | 204 | CC |
| 70% | 179 | B3 |
| 60% | 153 | 99 |
| 50% | 128 | 80 |
| 40% | 102 | 66 |
| 30% | 77 | 4D |
| 20% | 51 | 33 |
| 10% | 26 | 1A |
| 0% | 0 | 00 |
Decimal to hex in spreadsheets and calculators
Excel and Google Sheets provide DEC2HEX. The call =DEC2HEX(755) returns 2F3, and a second argument pads the result to a width: =DEC2HEX(755, 6) returns 0002F3. Excel accepts numbers from −549,755,813,888 to 549,755,813,887, the range of a 40-bit signed integer. A negative number comes back as a ten-digit two's complement string, so =DEC2HEX(-1) is FFFFFFFFFF and the width argument is ignored.
The Windows Calculator in Programmer mode converts as you type: choose DEC, enter the number and read the HEX line, which also shows negative numbers at the selected word size (QWORD, DWORD, WORD or BYTE). That makes it a quick way to see the stored form of a negative value at a chosen width. For numbers outside 64 bits, or for lists, a tool that works with arbitrary precision is necessary.
Timestamps, IDs and other decimal values that hide hex
Some decimal values are really hex fields in disguise. A Unix timestamp counts seconds since 1 January 1970, and 1,700,000,000 (14 November 2023, 22:13:20 UTC) is 6553F100 in hex. Seeing a timestamp as bytes explains how formats embed it: a MongoDB ObjectId begins with a four-byte timestamp, so the first eight hex digits of an ObjectId decode to the creation time in seconds. Converting those eight digits to decimal and then to a date is the standard way to read an ObjectId's age.
Counters, record numbers and database keys behave the same. A 32-bit counter that reaches 4,294,967,295 has used FFFFFFFF, and the next increment wraps to 0. A key that prints as 3,735,928,559 is DEADBEEF. When a decimal number looks arbitrary but a log shows it next to a hex value, converting it often reveals a recognizable pattern, such as a run of F digits, a repeated byte or a word.
Shortcuts for numbers near round hex values
You rarely need to run the full division. Numbers close to a power of 16 or of 2 can be converted by adjusting a known value. 4,095 is one less than 4,096 = 1000, so it is FFF. 65,534 is one less than 65,535 = FFFF, so it is FFFE. A multiple of 16 always ends in 0 and a multiple of 256 in 00, so 3,840 = 15 × 256 is F00. Halving or doubling shifts the digits: 512 is 200 because it is two times 256, and 2,048 is 800 because it is eight times 256.
These patterns are what experienced programmers use when they recognize 0x1000 as a page or 0xFFFF as a limit. The converter confirms them in a second; the value of knowing them is that a wrong digit stands out. If a tool shows 4,095 as 1000, you can see at once that one of you has made an error of one.
Mistakes that give the wrong hex
- Reading the remainders from the first to the last. The first remainder is the last digit, so the list has to be reversed.
- Writing a remainder of 10 to 15 as two characters. It is one digit: A, B, C, D, E or F.
- Stopping when the quotient reaches a number below 16 and forgetting that this number is itself the leading digit.
- Dropping a remainder of 0. A zero remainder is a zero digit: 256 gives the remainders 0, 0 and 1, which read upward as 100.
- Losing the leading zero in a fixed-width field. A byte with the value 10 is 0A, and #0A0A0A and #AAAAA are different things.
- Converting a number above 9,007,199,254,740,991 in a tool built on floating-point numbers, which rounds it before converting.
- Mixing up the stored form of a negative number with its absolute value. −1 in 8 bits is FF, and FF is also 255 as an unsigned byte; the width and signedness are not in the digits.
Decimal character codes to hex
Character tables often list decimal codes, and source code wants hex. The decimal code 233 is E9, which is the letter é in Latin-1 and in the Unicode code point U+00E9. It is not the byte sequence used for é in UTF-8, which is C3 A9: a code point and its encoded bytes only coincide for values below 128. The emoji at code point 128,512 is 1F600 in hex, written U+1F600, and takes four bytes in UTF-8 (F0 9F 98 80). When the number is the position of a character in Unicode, convert it as described here and then look at text to hex for the bytes.
Questions about converting decimal to hex
What is the hexadecimal of 23?
17. Divide 23 by 16: the quotient is 1 and the remainder is 7, so the digits are 1 and 7. As a check, 1 × 16 + 7 = 23.
What is 255 in hex?
FF. 255 divided by 16 is 15 remainder 15, and 15 is F in hex. It is the largest value one byte can hold, which is why FF turns up so often.
How do I convert a negative decimal number to hex?
Choose a width, then add 2 to the power of the bit count to the number. For −1 in 8 bits that is 256 − 1 = 255, written FF. For −255 in 16 bits it is 65,536 − 255 = 65,281, written FF01. The converter shows the smallest standard width that holds the value.
Why do hex numbers contain letters?
Base 16 needs sixteen distinct digits and the decimal system supplies only ten. The letters A to F stand for the values 10 to 15, so each position in a hex number can hold a single character.
Is there a limit to the size of the number?
Not in this converter, which uses arbitrary-precision integers, so a number with hundreds of digits converts exactly. Many programs limit integers to 64 bits (18,446,744,073,709,551,615, which is FFFFFFFFFFFFFFFF), and JavaScript numbers are exact only to 2^53 − 1.
