Number Theory & Bases

Hex to Decimal Converter

To convert hex to decimal, multiply each hex digit by its power of 16 and add the results: 1A3F16=1⋅163+10⋅162+3⋅16+15=6719\mathrm{1A3F}_{16} = 1 \cdot 16^3 + 10 \cdot 16^2 + 3 \cdot 16 + 15 = 6719.

Try

Digits 0–9 and letters A–Z as the base allows, an optional minus sign, and one point for a fractional part.

Result

1A3F (base 16) in base 10: 6719

1A3F (base 16) in base 10

6719106719_{10}

Digits in base 10
4 digits before the point
Binary, one group of 4 bits per hex digit
0001 1010 0011 1111
Signed 16-bit value (two’s complement)The top bit is 0, so signed and unsigned agree
6719

1A3F in hexadecimal (base 16) is 6719 in decimal (base 10).

The value of 1A3F (base 16) in other bases
BaseNameValue
2binary1101000111111
8octal15077
10decimal6719
16hexadecimal1A3F
Step-by-step working (2 steps)
  1. Expand in powers of 16

    Each digit is multiplied by 16 raised to the power of its position: 0 for the last integer digit, then 1, 2, … to the left and −1, −2, … to the right of the point. Letters stand for values above 9: A = 10, F = 15.

    1A3F16=1⋅163+10⋅162+3⋅161+15⋅160=4096+2560+48+15=6719\mathrm{1A3F}_{16} = 1 \cdot 16^{3} + 10 \cdot 16^{2} + 3 \cdot 16^{1} + 15 \cdot 16^{0} = 4096 + 2560 + 48 + 15 = 6719
  2. Result

    1A3F16=671910\mathrm{1A3F}_{16} = 6719_{10}

This converter shows that working for any input. It also converts decimal to hex, binary and octal, or between any bases from 2 to 36, with fractions and exact repeating digits.

By Hira Noor, mathematicianLast reviewed Free, no sign-up, runs in your browserReport a problem

How to use this calculator

  1. Type the number. Hex uses 0–9 and A–F (A = 10 up to F = 15), upper or lower case. A 0x prefix is accepted for hex, and 0b or 0o for binary and octal.
  2. The page opens on hex to decimal. To go the other way, set From base to 10 and To base to 16. As a general number base converter it handles any base from 2 to 36, with letters up to Z = 35.
  3. Use a minus sign for a negative number and one point for a fractional part, for example −1F.8.
  4. For fractions, set how many digits after the point to show if the expansion is long. Repeating blocks appear in parentheses as soon as they are found.

Formulas

Hex to decimal

(hk…h1h0)16=hk⋅16k+⋯+h1⋅16+h0(h_k \ldots h_1 h_0)_{16} = h_k \cdot 16^k + \cdots + h_1 \cdot 16 + h_0

Plain-text formula: (h_k…h_1h_0)_16 = h_k · 16^k + ⋯ + h_1 · 16 + h_0

hih_i
the hex digit in position i, from 0 to 15 (A = 10, …, F = 15)
kk
one less than the number of digits

Each hex digit is worth its value times a power of 16, counting the rightmost digit as power 0. Add the products to get the decimal value.

Positional notation in any base

(dk…d1d0.d−1d−2…)b=∑idibi(d_k \ldots d_1 d_0 . d_{-1} d_{-2} \ldots)_b = \sum_i d_i \, b^{i}

Plain-text formula: (d_k…d_1d_0.d_(−1)d_(−2)…)_b = ∑_{i} d_i b^i

bb
the base, 2 to 36
did_i
the digit in position i, from 0 to b − 1

The same rule works in every base, and digits after the point take negative powers. This is how a number in any base is turned into its value. Roman numerals are not positional, so they need the Roman numeral converter instead.

Repeated division (decimal to hex or any base)

n=q0b+r0,q0=q1b+r1,…⇒n=(rk…r1r0)bn = q_0 b + r_0,\quad q_0 = q_1 b + r_1,\quad \ldots \quad\Rightarrow\quad n = (r_k \ldots r_1 r_0)_b

Plain-text formula: n = q_0b + r_0, q_0 = q_1b + r_1, … ⇒ n = (r_k…r_1r_0)_b

Divide by the new base until the quotient is 0. The remainders are the digits, and the first remainder is the last digit.

Repeated multiplication (fractional part)

f⋅b=d−1+f1,f1⋅b=d−2+f2,…f \cdot b = d_{-1} + f_1,\quad f_1 \cdot b = d_{-2} + f_2,\quad \ldots

Plain-text formula: f · b = d_(−1) + f_1, f_1 · b = d_(−2) + f_2, …

The whole-number part of each product is the next digit after the point. If a fractional part repeats, so do all the digits after it.

Reading the result

The main result is the converted number. For hex or binary input, the result panel also gives the signed value: the same digits read as a two’s complement integer at the narrowest of 8, 16, 32 or 64 bits that holds them. FF is 255 unsigned but −1 as a signed byte. Use the binary calculator for fixed word sizes, overflow and bitwise operations.

A fraction ends in base b exactly when its denominator, in lowest terms, has only prime factors of b. One tenth is 12⋅5\frac{1}{2 \cdot 5}, and 5 does not divide 2 or 16, so 0.1 has no finite binary or hex form. That is why 0.1 + 0.2 is not exactly 0.3 in most programming languages, which store numbers in binary.

How to convert hex to decimal

Write down the place value of each position, starting from 1 on the right and multiplying by 16 each step left: 1, 16, 256, 4096 and so on. Replace any letters by their values (A = 10, B = 11, C = 12, D = 13, E = 14, F = 15). Multiply each digit by its place value and add the products.

For example, 2F = 2 × 16 + 15 = 47, and 1F4 = 1 × 256 + 15 × 16 + 4 = 500. To go from decimal to hex, divide by 16 repeatedly and read the remainders from the last to the first: 500 ÷ 16 = 31 r 4, 31 ÷ 16 = 1 r 15 (F), 1 ÷ 16 = 0 r 1, so 500 = 1F4.

Place values of the first eight hex digits
Position (from right)Power of 16Place value
1st16⁰1
2nd16¹16
3rd16²256
4th16³4,096
5th16⁴65,536
6th16⁵1,048,576
7th16⁶16,777,216
8th16⁷268,435,456

Hex to decimal table

The single hex digits 0 to F match the decimal numbers 0 to 15, and each is exactly four binary digits. Two hex digits make one byte, from 00 to FF (0 to 255). The rows below cover the digits and the two-digit values people look up most often.

A common trap: hex 10 is 16, not ten, and hex 20 is 32. Hex 100 is 256, so every extra hex digit multiplies the range by 16.

Hex, decimal and binary equivalents
HexDecimalBinary
000000
110001
220010
330011
440100
550101
660110
770111
881000
991001
A101010
B111011
C121100
D131101
E141110
F151111
10160001 0000
16220001 0110
20320010 0000
32500011 0010
40640100 0000
641000110 0100
7F1270111 1111
801281000 0000
FF2551111 1111
1002560001 0000 0000
3E81,0000011 1110 1000
FFFF65,5351111 1111 1111 1111

Binary to hexadecimal and back

To convert binary to decimal, add the place values (1, 2, 4, 8, 16, …) wherever the bit is 1: 1101 = 8 + 4 + 1 = 13. The binary to decimal converter shows that working bit by bit, with signed two’s complement values and binary fractions.

To convert binary to hexadecimal, group the bits in fours from the right and replace each group with one hex digit from the table above. 1111 1111 = FF, 1010 1010 = AA and 1 0000 0000 = 100. For octal, group in threes instead: 11 111 111 = 377. Hex to binary is the same process backward, four bits per digit.

Negative hex numbers and two’s complement

A minus sign in front, such as −1F, simply means −31; the converter handles it by converting the size and keeping the sign. In programming, though, negative numbers are usually stored in two’s complement, where the same digits can mean two things. In 8 bits, FF is 255 unsigned and −1 signed; in 16 bits, 8000 is 32,768 unsigned and −32,768 signed.

To read a hex value as signed, check its top bit at the word size you care about. If the top bit is 1, subtract 2w2^w from the unsigned value, where w is the number of bits: FF₁₆ = 255, and 255 − 256 = −1. The result panel does this for you at 8, 16, 32 or 64 bits.

Hex to decimal in code and spreadsheets

Most languages have a built-in base converter. In Python, int("1A3F", 16) returns 6719, and hex(6719) gives back "0x1a3f". In JavaScript, parseInt("1A3F", 16) returns 6719 and (6719).toString(16) returns "1a3f"; for values above 2532^{53} use BigInt("0xFFFFFFFFFFFFFFFF"). In C, strtoul("1A3F", NULL, 16) does the same for unsigned values.

In Excel and Google Sheets, =HEX2DEC("1A3F") returns 6719. HEX2DEC accepts at most 10 hex digits and reads them as a signed 40-bit number, so =HEX2DEC("FFFFFFFFFF") is −1, not 1,099,511,627,775. Use this converter when you need longer values or the unsigned reading.

Common mistakes

Reading remainders in the wrong order. When dividing by 16 or 2, the first remainder is the last digit. Writing them in the order found reverses the number.

Treating hex 10 as ten. It is 16. Hex numbers without letters, such as 20 or 99, still use powers of 16.

Confusing the letter O with zero, or I with one. Hex only uses A to F. Bases above 16 use more letters, but O and I are still digits there (O = 24, I = 18), so check the base.

Losing precision on very large values. Spreadsheet and JavaScript numbers are exact only up to 2532^{53}, about 9 × 10¹⁵, so a 64-bit hex value such as FFFFFFFFFFFFFFFF can come back wrong. This converter uses exact integer arithmetic for up to 120 digits.

Worked example

Convert hex 1A3F to decimal

Write the hexadecimal number 1A3F in base 10.

  1. Replace the letters by their values: 1, A = 10, 3, F = 15.
  2. Give each digit its place value, from the right: 16⁰ = 1, 16¹ = 16, 16² = 256, 16³ = 4096.
  3. Multiply: 1 × 4096 = 4096, 10 × 256 = 2560, 3 × 16 = 48 and 15 × 1 = 15.
  4. Add the products: 4096 + 2560 + 48 + 15 = 6719.
  5. Check by converting back: 6719 ÷ 16 = 419 r 15 (F), 419 ÷ 16 = 26 r 3, 26 ÷ 16 = 1 r 10 (A), 1 ÷ 16 = 0 r 1. Reading upward gives 1A3F.

Answer: 1A3F₁₆ = 6719₁₀. In binary it is 0001 1010 0011 1111, one group of four bits per hex digit.

Frequently asked questions

How do I convert hex to decimal?

Multiply each hex digit by 16 raised to its position, counting from 0 on the right, and add the results. Letters count as A = 10 to F = 15. For example 2F = 2 × 16 + 15 = 47.

What is FF in decimal?

FF is 255: F × 16 + F = 15 × 16 + 15. It is the largest two-digit hex number and the largest value of one unsigned byte. As a signed 8-bit number, FF is −1.

How do I convert decimal to hex?

Divide by 16 repeatedly and read the remainders from the last to the first, writing 10 to 15 as A to F. For 255: 255 ÷ 16 = 15 r 15, then 15 ÷ 16 = 0 r 15, so 255 = FF.

What does 0x mean in front of a hex number?

It is a prefix that marks the number as hexadecimal, used in C, Python, JavaScript and most other languages. 0x1F means hex 1F, which is 31. You can paste numbers with the 0x prefix straight into the converter.

How do I convert decimal to binary?

Divide by 2 repeatedly and read the remainders upward: 13 ÷ 2 = 6 r 1, 6 ÷ 2 = 3 r 0, 3 ÷ 2 = 1 r 1, 1 ÷ 2 = 0 r 1, so 13 = 1101. The decimal to binary converter shows those divisions for any number, with 8- to 64-bit padding, and the binary to decimal converter goes the other way.

Why does 0.1 repeat in binary?

Because 0.1 = 1/10 and 10 has the prime factor 5, which 2 does not share. The binary digits repeat forever: 0.1 = 0.0(0011)₂. In hex the same value is 0.1(9)₁₆, which also never ends.

How large a number can this convert?

Up to 120 digits, exactly. The converter uses whole-number arithmetic with no rounding, so 64-bit values such as FFFFFFFFFFFFFFFF = 18,446,744,073,709,551,615 come out exact, unlike in a spreadsheet.

Decimal to Binary Converter

Decimal to binary with each division by 2, padding to 8–64 bits, two’s complement and fractions.

Number Theory & Bases

Binary to Decimal Converter

Binary to decimal with each bit’s power of 2 and a running total, signed or unsigned, fractions included.

Number Theory & Bases

Binary Calculator

Binary addition, subtraction and bitwise operations with steps, at 8 to 64 bits, signed or unsigned.

Number Theory & Bases

Mod Calculator

a mod n with steps, negative numbers, power mod and modular inverses.

Number Theory & Bases

Decimal to Fraction Calculator

Decimals and repeating decimals to fractions in lowest terms, and fractions back to decimals, with steps.

Arithmetic & Numbers

Scientific Calculator

Type or tap expressions with exact fractions, memory, variables, constants and complex mode.

Tools

Learn more: For base-n arithmetic and bitwise operations in the full calculator, read base-n and bitwise operations. Why 0.1 has no exact binary form: floating point and rounding.

Sources and further reading

  1. The Art of Computer Programming, Volume 2: Seminumerical Algorithms, 3rd edition, §4.1 Positional Number Systems and §4.4 Radix Conversion, Addison-Wesley (Donald E. Knuth, 1997)
  2. IEEE Standard for Floating-Point Arithmetic (IEEE 754-2019) (opens in a new tab), Institute of Electrical and Electronics Engineers (2019)
  3. Python documentation: int() and integer literals (0x, 0o, 0b prefixes, bases 2 to 36) (opens in a new tab), Python Software Foundation
  4. HEX2DEC function (opens in a new tab), Microsoft Support
  5. Number.MAX_SAFE_INTEGER (opens in a new tab), MDN Web Docs (Mozilla)

Results are calculated in your browser with methods checked by automated tests, and are intended for learning and general use. For engineering, medical, financial, legal or safety-critical decisions, verify important values independently and follow the rounding rules your work requires. How accurate are these results?