Hex to Decimal Converter
Multiply each hex digit by 16 raised to its position, counted from the right, and add the results: 2F3 = 2 × 256 + 15 × 16 + 3 = 755. The converter does this for a value or a list, with a 0x prefix or without, and shows the signed reading at 8, 16, 32 and 64 bits. Everything is calculated in your browser.
Step-by-step conversion
(2F3)₁₆ = (2 × 16²) + (15 × 16¹) + (3 × 16⁰) = (2 × 256) + (15 × 16) + (3 × 1) = 512 + 240 + 3 = 755
| Digit | Value | Weight | Product |
|---|---|---|---|
| 2 | 2 | 16^2 = 256 | 512 |
| F | 15 | 16^1 = 16 | 240 |
| 3 | 3 | 16^0 = 1 | 3 |
As a signed two's complement integer: 16-bit 755 · 32-bit 755 · 64-bit 755
How to convert hex to decimal by hand
Hexadecimal is a positional system with base 16, so each digit has a weight that is a power of 16, counting from the right. The rightmost digit is multiplied by 16^0, which is 1. The next is multiplied by 16^1 = 16, then 16^2 = 256, then 16^3 = 4,096, and so on. Multiply every digit by its weight, add the products, and the sum is the decimal value. Digits A to F count as 10 to 15.
The weights grow quickly, which is why a few of them are worth knowing by heart. Each extra digit multiplies the range by 16, and every two digits make a byte, so 16^2 = 256 is the number of values in a byte.
| Power | Decimal | Hex |
|---|---|---|
| 16^0 | 1 | 1 |
| 16^1 | 16 | 10 |
| 16^2 | 256 | 100 |
| 16^3 | 4,096 | 1000 |
| 16^4 | 65,536 | 10000 |
| 16^5 | 1,048,576 | 100000 |
| 16^6 | 16,777,216 | 1000000 |
| 16^7 | 268,435,456 | 10000000 |
| 16^8 | 4,294,967,296 | 100000000 |
Hex digits A to F and their values
A hex digit stands for four bits. The ten decimal digits cover 0 to 9, and the letters supply the six values that would otherwise need two characters. Upper and lower case mean the same thing: b and B are both 11.
| Hex digit | Decimal | Binary (4 bits) |
|---|---|---|
| 0 | 0 | 0000 |
| 1 | 1 | 0001 |
| 2 | 2 | 0010 |
| 3 | 3 | 0011 |
| 4 | 4 | 0100 |
| 5 | 5 | 0101 |
| 6 | 6 | 0110 |
| 7 | 7 | 0111 |
| 8 | 8 | 1000 |
| 9 | 9 | 1001 |
| A | 10 | 1010 |
| B | 11 | 1011 |
| C | 12 | 1100 |
| D | 13 | 1101 |
| E | 14 | 1110 |
| F | 15 | 1111 |
Worked example: 2F3 is 755
2F3 has three digits, so the weights are 256, 16 and 1. The 2 is worth 2 × 256 = 512. The F is 15, worth 15 × 16 = 240. The 3 is worth 3 × 1 = 3. Add them: 512 + 240 + 3 = 755.
| Digit | Digit value | Weight | Digit × weight |
|---|---|---|---|
| 2 | 2 | 16^2 = 256 | 512 |
| F | 15 | 16^1 = 16 | 240 |
| 3 | 3 | 16^0 = 1 | 3 |
| Total | 755 |
There is a second way to do the same sum that needs no powers. Start with the first digit and, for each following digit, multiply the running total by 16 and add the digit. For 2F3: start at 2; 2 × 16 + 15 = 47; 47 × 16 + 3 = 755. Programs use this form because it handles any length with one multiplication per digit, and it is easier on paper once the number passes four digits.
A longer example: 1D2A3FB is 30,581,755
With seven digits the leftmost weight is 16^6 = 16,777,216. The digit D is 13, so it contributes 13 × 1,048,576 = 13,631,488. The sum of all seven products is 30,581,755.
| Digit | Digit value | Weight | Digit × weight |
|---|---|---|---|
| 1 | 1 | 16^6 = 16,777,216 | 16,777,216 |
| D | 13 | 16^5 = 1,048,576 | 13,631,488 |
| 2 | 2 | 16^4 = 65,536 | 131,072 |
| A | 10 | 16^3 = 4,096 | 40,960 |
| 3 | 3 | 16^2 = 256 | 768 |
| F | 15 | 16^1 = 16 | 240 |
| B | 11 | 16^0 = 1 | 11 |
| Total | 30,581,755 |
A quick estimate catches slips: the leading digit times its weight gives the floor of the answer (here 16,777,216) and the leading digit plus one gives the ceiling (33,554,432). The result 30,581,755 is between them, and closer to the ceiling because the second digit D is large.
Converting through binary
Because 16 is 2^4, every hex digit is exactly four bits, and a hex number can be rewritten as binary by replacing each digit with its group of four. 2F3 becomes 0010 1111 0011, which is 1011110011 once the leading zeros are dropped. Add the weights of the ones, 512 + 128 + 64 + 32 + 16 + 2 + 1, and the result is 755 again. This route is slower for plain conversion but it is the one to use when the bits matter, for example when checking a flag register or a bit mask. The same digits as binary have their own page: hex to binary.
Checking your answer
Two cheap tests catch most arithmetic slips. The last hex digit is the remainder of the value divided by 16, so the decimal number must be odd exactly when the last hex digit is odd: 2F3 ends in 3, and 755 is odd. The second test uses the fact that 16 is one more than 15. Adding up the values of the hex digits gives a number with the same remainder modulo 15 as the full value. For 2F3 the digits give 2 + 15 + 3 = 20, which leaves 5 after dividing by 15, and 755 leaves 5 as well. For 1D2A3FB the sum is 55 and the remainder is 10; 30,581,755 also leaves 10. A mismatch means a product or a sum is wrong; a match does not prove the answer, but a wrong one passes it only about one time in fifteen.
Fractions: hex digits after a point
The weights continue below the point as 16^−1, 16^−2 and so on, which are 1/16, 1/256 and smaller. 2F.8 is 2 × 16 + 15 + 8/16 = 47.5, and 0.A is 10/16 = 0.625. Hex fractions with a short expansion are always exact in decimal, but the reverse fails: decimal 0.1 is 0.1999… in hex and repeats forever, which is the reason floating-point values such as 0.1 cannot be stored exactly. The converter on this page handles whole numbers only; floating-point hex is a separate topic, covered by hex to float.
Hex to decimal answers people look up
Some values are searched for again and again because they are the limits of common integer types or turn up in logs and source code. They are collected here, computed with the same routine as the converter above. Any other value goes into the converter above.
| Hex | Decimal | Why it comes up |
|---|---|---|
| 33 | 51 | The ASCII digit 3; also 3 × 16 + 3 |
| FF | 255 | Largest value of one byte |
| 100 | 256 | 256: one more than a byte holds |
| 3E8 | 1,000 | One thousand |
| 7FFF | 32,767 | Largest signed 16-bit integer |
| FFFF | 65,535 | Largest unsigned 16-bit integer, and the highest TCP and UDP port number |
| 7FFFFFFF | 2,147,483,647 | Largest signed 32-bit integer (INT_MAX) |
| FFFFFFFF | 4,294,967,295 | Largest unsigned 32-bit integer; −1 when read as signed |
The question in the other direction, what is the hexadecimal of 23, has a short answer: 23 divided by 16 is 1 remainder 7, so decimal 23 is hex 17. Converting decimal to hex is the reverse procedure, repeated division by 16 with the remainders read from the last to the first, and has its own page: decimal to hex.
Signed hex: two's complement at 8, 16, 32 and 64 bits
Hex shows bits and does not carry a sign. Whether FF is 255 or −1 depends on the type of the value, and the type is not in the digits. Processors store signed integers in two's complement: the top bit has a negative weight. In an 8-bit value the weights are −128, 64, 32, 16, 8, 4, 2, 1. The byte FF has every bit set, so it is −128 + 127 = −1.
To read a hex value as signed by hand, first decide the width, which is the number of digits in the type and not in the number you were given (a 32-bit integer is eight hex digits, so 7F is written 0000007F). If the top bit is clear, meaning the first hex digit is 0 to 7, the value is the same as unsigned. If the first digit is 8 to F, subtract 2^bits from the unsigned value: FFFFFFFF is 4,294,967,295 − 4,294,967,296 = −1. The reverse, writing a negative number as hex, adds 2^bits: −2 as 8 bits is 256 − 2 = FE.
| Hex | Width | Unsigned | Signed |
|---|---|---|---|
| 7F | 8-bit | 127 | 127 |
| 80 | 8-bit | 128 | −128 |
| FF | 8-bit | 255 | −1 |
| 7FFF | 16-bit | 32,767 | 32,767 |
| 8000 | 16-bit | 32,768 | −32,768 |
| FFFF | 16-bit | 65,535 | −1 |
| 7FFFFFFF | 32-bit | 2,147,483,647 | 2,147,483,647 |
| 80000000 | 32-bit | 2,147,483,648 | −2,147,483,648 |
| FFFFFFFF | 32-bit | 4,294,967,295 | −1 |
The width changes the answer for the same digits. FF as an 8-bit value is −1, but as a 16-bit value (00FF) it is 255, because the top bit of the wider type is 0. When you enter a single value in the converter, the signed readings are listed for every width that is large enough to hold the digits you typed. A leading minus sign is also accepted: −FF is −255, and in 16 bits it is stored as FF01.
Reading multi-byte values from a dump: byte order
Values copied from a memory dump, a network capture or a file header are often several bytes long, and the order of those bytes changes the number. Most desktop and mobile processors store integers little-endian: the least significant byte comes first. Network protocols and many file formats use big-endian, called network byte order, with the most significant byte first. The decimal value 755 (hex 2F3) as a 32-bit integer is F3 02 00 00 in a little-endian dump and 00 00 02 F3 in a big-endian one.
To convert, write the bytes in the order of significance first, then convert as usual. The two bytes E8 03 in little-endian are 03E8 once reversed, which is 1,000. Read in the wrong order they become E803 = 59,395. A result that is wildly off by a factor of 256 or 65,536, or that suddenly looks plausible after reversing the pairs, points at byte order. The text version of this problem is the UTF-16 byte order discussed on the hex decoder page.
Hex to decimal conversion table, 00 to FF
Every two-digit hex value, laid out as a grid: find the first digit in the left column and the second digit in the top row. The cell is the decimal value. For example, row 2 and column F is 2F = 47, the running total from the by-hand example above. The rows step by 16, so the first column is 0, 16, 32, 48 and so on.
| 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | A | B | C | D | E | F | |
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
| 0 | 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 |
| 1 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 |
| 2 | 32 | 33 | 34 | 35 | 36 | 37 | 38 | 39 | 40 | 41 | 42 | 43 | 44 | 45 | 46 | 47 |
| 3 | 48 | 49 | 50 | 51 | 52 | 53 | 54 | 55 | 56 | 57 | 58 | 59 | 60 | 61 | 62 | 63 |
| 4 | 64 | 65 | 66 | 67 | 68 | 69 | 70 | 71 | 72 | 73 | 74 | 75 | 76 | 77 | 78 | 79 |
| 5 | 80 | 81 | 82 | 83 | 84 | 85 | 86 | 87 | 88 | 89 | 90 | 91 | 92 | 93 | 94 | 95 |
| 6 | 96 | 97 | 98 | 99 | 100 | 101 | 102 | 103 | 104 | 105 | 106 | 107 | 108 | 109 | 110 | 111 |
| 7 | 112 | 113 | 114 | 115 | 116 | 117 | 118 | 119 | 120 | 121 | 122 | 123 | 124 | 125 | 126 | 127 |
| 8 | 128 | 129 | 130 | 131 | 132 | 133 | 134 | 135 | 136 | 137 | 138 | 139 | 140 | 141 | 142 | 143 |
| 9 | 144 | 145 | 146 | 147 | 148 | 149 | 150 | 151 | 152 | 153 | 154 | 155 | 156 | 157 | 158 | 159 |
| A | 160 | 161 | 162 | 163 | 164 | 165 | 166 | 167 | 168 | 169 | 170 | 171 | 172 | 173 | 174 | 175 |
| B | 176 | 177 | 178 | 179 | 180 | 181 | 182 | 183 | 184 | 185 | 186 | 187 | 188 | 189 | 190 | 191 |
| C | 192 | 193 | 194 | 195 | 196 | 197 | 198 | 199 | 200 | 201 | 202 | 203 | 204 | 205 | 206 | 207 |
| D | 208 | 209 | 210 | 211 | 212 | 213 | 214 | 215 | 216 | 217 | 218 | 219 | 220 | 221 | 222 | 223 |
| E | 224 | 225 | 226 | 227 | 228 | 229 | 230 | 231 | 232 | 233 | 234 | 235 | 236 | 237 | 238 | 239 |
| F | 240 | 241 | 242 | 243 | 244 | 245 | 246 | 247 | 248 | 249 | 250 | 251 | 252 | 253 | 254 | 255 |
Hex to int: what fits in 8, 16, 32 and 64 bits
Converting to an int is the same arithmetic, followed by a question: does the value fit in the type? The widest hex string that fits in n bits has n / 4 digits, and the type then decides how the result is read. A string longer than the type is an overflow, which is a common cause of a conversion that returns zero, a negative number or a wrong one.
| Bits | Hex digits | Largest hex | Largest unsigned | Signed range |
|---|---|---|---|---|
| 8 | 2 | FF | 255 | −128 to 127 |
| 16 | 4 | FFFF | 65,535 | −32,768 to 32,767 |
| 32 | 8 | FFFFFFFF | 4,294,967,295 | −2,147,483,648 to 2,147,483,647 |
| 64 | 16 | FFFFFFFFFFFFFFFF | 18,446,744,073,709,551,615 | −9,223,372,036,854,775,808 to 9,223,372,036,854,775,807 |
JavaScript is the usual place this bites. Numbers are 64-bit floating point values, and integers are exact only up to 2^53 − 1 = 9,007,199,254,740,991, which is 1FFFFFFFFFFFFF in hex (14 digits). parseInt("FFFFFFFFFFFFFFFF", 16) returns 18446744073709552000 and not 18446744073709551615, because the low digits are lost. The converter on this page uses arbitrary-precision integers, so a 64-digit hex string is converted exactly. See Number.MAX_SAFE_INTEGER on MDN for the limit.
A quick way to size a result before converting: each hex digit adds about 1.2 decimal digits, because log10 of 16 is 1.204. Eight hex digits are at most 10 decimal digits (4,294,967,295) and sixteen are at most 20 (18,446,744,073,709,551,615). Round hex numbers are worth memorizing as sizes, since memory and address spaces are built from them.
| Hex | Decimal | Size |
|---|---|---|
| 1000 | 4,096 | 4 KiB, a common memory page |
| 10000 | 65,536 | 64 KiB; 65,536 values in 16 bits |
| 100000 | 1,048,576 | 1 MiB |
| 1000000 | 16,777,216 | 16 MiB; the number of 24-bit colors |
| 40000000 | 1,073,741,824 | 1 GiB |
| 100000000 | 4,294,967,296 | 4 GiB; the size of a 32-bit address space |
Convert a list of hex values at once
Paste several values, one per line or separated by commas, spaces or semicolons, and each is converted on its own line in the same order. That covers a column copied from a spreadsheet, an array of constants from source code (0x1F, 0x2A, 0xFF) or a list of addresses. The output is one decimal number per line, so it can be pasted back into a spreadsheet or into an array literal after adding commas.
A bad entry does not stop the rest. The line for the value that failed is left empty, the message names the entry and the offending character, and the Show button jumps to the character in the input. With several values the signed readings and place-value table are not shown; enter one value to see them.
Hex to decimal in Python, JavaScript, C and the shell
Every language has a one-line conversion. The differences are in what happens to a prefix, an invalid digit and a value that is too large.
int("2F3", 16) # 755
int("0x2F3", 16) # 755; the prefix is accepted when the base is 16
int("1D2A3FB", 16) # 30581755; Python integers have no size limit
# signed 32-bit reading of eight hex digits
int.from_bytes(bytes.fromhex("FFFFFFFF"), "big", signed=True) # -1int() raises ValueError for any character outside the base, and also for a trailing h. See the Python documentation for int.
parseInt("2F3", 16) // 755
Number("0x2F3") // 755
BigInt("0x1D2A3FB") // 30581755n, exact for any length
parseInt("2F3xyz", 16) // 755; stops at the first invalid character
parseInt("FFFFFFFFFFFFFFFF", 16) // 18446744073709552000: precision lost#include <stdlib.h>
unsigned long v = strtoul("2F3", NULL, 16); /* 755 */
unsigned long long w = strtoull("FFFFFFFFFFFFFFFF", NULL, 16); /* 18446744073709551615 */
sscanf("2F3", "%x", &x); /* x is unsigned int */strtoul accepts a 0x prefix when the base is 16 and sets endptr to the first character it could not use, which is how you detect trailing junk.
echo $((16#2F3)) # 755
printf '%d\n' 0x2F3 # 755
[Convert]::ToInt32("2F3", 16) # 755
[Convert]::ToInt32("FFFFFFFF", 16) # -1: ToInt32 reads the result as signed
[Convert]::ToUInt32("FFFFFFFF", 16) # 4294967295Spreadsheets and databases have the function too. Excel and Google Sheets use =HEX2DEC("2F3"). In Excel the argument is limited to 10 hex characters (40 bits), and the top bit of those 40 is treated as a sign, so FFFFFFFFFF returns −1. MySQL converts with CONV('2F3', 16, 10), which returns the text '755', or with a hex literal in arithmetic: 0x2F3 + 0.
Handling very long hex strings
Strings longer than 16 digits no longer fit in a 64-bit integer, so tools that use the native number type of their language stop being exact. Python, Java's BigInteger and JavaScript's BigInt all keep every digit. In C there is no standard type beyond unsigned long long, which tops out at 18,446,744,073,709,551,615, and the usual answer is a big-number library. Cryptographic values show the scale: a SHA-256 digest is 64 hex digits, up to 78 decimal digits, and an RSA modulus can run to 1,000 hex digits or more. They convert correctly here because the arithmetic does not round. Be careful when pasting a long value into a spreadsheet, because spreadsheets store numbers as 64-bit floating point and silently keep only 15 significant digits.
Leading zeros do not change an unsigned value, and the converter accepts them, so a fixed-width field such as 000000FF converts to 255. For signed readings the width counts, because the digits are padded to the width of the type and not to the width you typed. When the width is not known, the table of signed readings above lists each candidate and the source of the hex has to decide.
Common mistakes when converting hex to decimal
- Starting the weights at 16^1. The rightmost digit has weight 16^0 = 1, so the last digit is added as it is.
- Adding the digit values without weighting them. 2F3 is not 2 + 15 + 3 = 20.
- Reading A as 1, B as 2 and so on. A is 10 and F is 15.
- Treating 10 as ten. Hex 10 is 16, hex 100 is 256 and hex 64 is 100.
- Confusing similar characters when the hex was typed from a screenshot: 0 and O, 1 and l, 5 and S, 8 and B. Only 0-9 and A-F are digits.
- Dropping leading zeros and then reading the number as signed. 0080 is 128; 80 as an 8-bit value is −128.
- Calling JavaScript's parseInt without the base.
parseInt("10")returns 10, whileparseInt("10", 16)returns 16, andparseInt("0x10")returns 16 because the prefix is detected.
Where decimal values from hex show up
Hex is what tools print; decimal is what people compare against. Windows error codes are a typical case. HRESULT 0x80070005 is E_ACCESSDENIED. As an unsigned number it is 2,147,942,405, and as a signed 32-bit integer, which is how many logs and debuggers print it, it is −2,147,024,891. Searching for either decimal form finds the same error.
IPv4 addresses are four bytes, so C0A80001 is 192.168.0.1 when each pair is converted separately: C0 = 192, A8 = 168, 00 = 0, 01 = 1. Treating the same digits as one number gives 3,232,235,521, which is also valid as an address in many tools. Unicode code points are written in hex (U+00E9) and are 233 in decimal, and a CSS color such as FF8800 is three values, 255, 136 and 0, handled by the hex to RGB converter. If the digits you have are the bytes of a message and not a number, decode them as text instead.
Network tools print ports in hex as well. A packet capture shows the destination port of a web request as 01BB, which is 443, and a development server on 1F90 is listening on 8080. HTTP's own port 80 is 50 in hex. The same habit explains why a byte count in a file header is easier to read once converted: a length field of 00 00 10 00 is 4,096 bytes when read big-endian.
Questions about converting hex to decimal
What is 7FFFFFFF in decimal?
2,147,483,647, which is 2^31 − 1: the largest value of a signed 32-bit integer. The next hex value, 80000000, is 2,147,483,648 unsigned and −2,147,483,648 as a signed 32-bit integer.
What is 33 hex in decimal?
51: 3 × 16 + 3. As text the byte 33 is the digit character 3, so a hex string made of 33 pairs can be a string of digits.
Why is FFFFFFFF sometimes −1?
Hex does not say whether a value is signed. Read as an unsigned 32-bit number FFFFFFFF is 4,294,967,295. Read as a signed 32-bit number, whose top bit is a sign bit, the same 32 ones mean −1. The type in the program or file format decides which one is right.
Can you convert hex to decimal without a calculator?
Yes, for short values. Write the digits with their weights (1, 16, 256, 4096 from the right), multiply each digit by its weight and add. For three digits the arithmetic is small: 2F3 is 512 + 240 + 3. Memorizing 16, 256 and 4,096 makes four-digit values quick.
Does the converter handle 0x prefixes and lowercase?
Yes. 0x2f3, 2F3, 2f3 and 2F3h all give 755, and underscores are ignored, so 0xFFFF_FFFF works. A minus sign in front gives a negative result. Any character outside 0-9 and A-F is reported with its position.
