Hex to Decimal

Hex to decimal

Signed as

Each digit times its place value

Tap a switch to flip a bit

Binary
Octal
Size

How to use the hex to decimal converter

To use the converter, type a hex number in the Hexadecimal box and read its decimal value in the Decimal box.

  1. Type or paste a hex number such as 1A2B, 0x1A2B, #1A2B or 1A2Bh, in upper or lower case.
  2. Read the decimal value in the green box, which updates on every keystroke.
  3. Check the breakdown below, which shows each digit, its power of 16 and its share of the total.
  4. Type in the Decimal box instead to convert decimal to hex and see the divide-by-16 steps.

Tap any bit switch to flip that bit and watch both values change together. A link such as hextodecimal.net/?hex=FF opens the converter with that number filled in.

Try a value

Tap one, the converter follows
You type
Each digit × 16ⁿ
You get

How to convert hex to decimal

To convert hex to decimal, multiply each hex digit by 16 raised to the power of its position, then add the products. Positions count from 0 on the right, so the place values run 1, 16, 256, 4,096 and 65,536.

Hex to decimal formula
decimal = dₙ×16ⁿ + … + d₂×16² + d₁×16¹ + d₀×16⁰
d = the value of each hex digit, from 0 to 15
n = the position of that digit, counted from 0 on the right
  1. Replace each letter with its decimal value: A = 10, B = 11, C = 12, D = 13, E = 14 and F = 15.
  2. Number the digit positions from right to left, starting at 0.
  3. Multiply each digit value by 16 raised to the power of its position.
  4. Add the products to get the decimal number.

Example 1: convert 2F to decimal

Hex 2F equals 47 in decimal, since the 2 sits in the 16s place and F (15) sits in the 1s place.

2F in decimal
2F = 2×16¹ + F×16⁰
   = 2×16 + 15×1
   = 32 + 15
   = 47

Try 2F in the converter

Example 2: convert 1A2B to decimal

Hex 1A2B equals 6,699 in decimal, and its 4 digits use the place values 4,096, 256, 16 and 1.

1A2B in decimal
1A2B = 1×16³ + A×16² + 2×16¹ + B×16⁰
     = 1×4,096 + 10×256 + 2×16 + 11×1
     = 4,096 + 2,560 + 32 + 11
     = 6,699

Try 1A2B in the converter

Example 3: convert 0x3E8 to decimal

Hex 0x3E8 equals 1,000 in decimal, and the 0x prefix only marks the number as hexadecimal without adding any value.

0x3E8 in decimal
3E8 = 3×16² + E×16¹ + 8×16⁰
    = 3×256 + 14×16 + 8×1
    = 768 + 224 + 8
    = 1,000

Try 3E8 in the converter

4 common conversion mistakes

Four mistakes cause most wrong answers in hex to decimal conversion, and each one is easy to spot once you know it.

  • Counting positions from 1 instead of 0, which makes every place value 16 times too large.
  • Reading hex digits as decimal, so hex 20 comes out as 20 instead of the correct value, 32.
  • Mixing up letter values, such as treating B as 12 when B equals 11.
  • Ignoring the bit width, so FF reads as 255 when the data holds a signed 8-bit value of −1.

Place-value calculator

Step a digit up or down

Hex to decimal conversion table

Each hex digit stands for 4 bits, called a nibble, so 2 hex digits always make 1 byte (8 bits). The chart shows all 16 hex digits with their decimal and binary values, and each digit loads into the converter when you tap it.

Common hex values in decimal
HexDecimalWhere it appears
1016The first two-digit hex number
2032The space character in ASCII
4165Capital A in ASCII
7F127The largest signed 8-bit value
80128The lowest signed 8-bit value, −128
FF255The largest value in 1 byte
100256The number of values 1 byte can hold
4001,0241 kibibyte (KiB)
7FFF32,767The largest signed 16-bit value
FFFF65,535The largest 16-bit value and the highest network port
7FFFFFFF2,147,483,647The largest signed 32-bit value
FFFFFFFF4,294,967,295The largest 32-bit value

Byte explorer

Slide, tap the grid or flip a bit
DecimalASCII

Hexadecimal and decimal number systems

Hexadecimal and decimal are positional number systems that differ in their base: hexadecimal is base 16, and decimal is base 10. Decimal is also called denary in UK schools and GCSE courses, so hex to denary means the same conversion.

Hexadecimal numbers (base 16)

A hexadecimal (hex) number uses 16 digits, 0 to 9 and A to F, and each place is worth 16 times the place to its right.

Programmers write memory addresses, colour codes and binary data in hex, since 1 hex digit maps to exactly 4 bits. Code and documents mark hex numbers with a 0x prefix (0xFF), a # sign (#FF0000) or an h suffix (FFh).

Decimal numbers (base 10)

A decimal number uses 10 digits, 0 to 9, and each place is worth 10 times the place to its right.

People count, price and measure in decimal, so software shows most numbers in decimal even when it stores them in binary.

Hex vs decimal compared

Hex and decimal differ in 7 main features, from the digits they use to the jobs they do.

FeatureHexadecimalDecimal
Base1610
Digits0–9 and A–F0–9
Place values1, 16, 256, 4,0961, 10, 100, 1,000
Bits per digitExactly 4About 3.32
Largest 1-byte valueFF255
Usual markers0x, #, h suffixNone
Main useMemory, colours, machine codeCounting, prices, everyday maths

Same number, four bases

Follows the converter
Binary base 2
Octal base 8
Decimal base 10
Hexadecimal base 16

Hex fractions to decimal

To convert a hex fraction to decimal, multiply each digit after the point by a negative power of 16 and add the results to the whole part. The first place after the point is worth 1/16 (0.0625), and the second place is worth 1/256 (0.00390625).

1F.4 in decimal
1F.4 = 1×16¹ + F×16⁰ + 4×16⁻¹
     = 16 + 15 + 4/16
     = 31 + 0.25
     = 31.25

The converter above handles whole numbers, so work out the fractional part by hand and add it to the whole-number result.

Hex fraction calculator

Type a point, such as 1F.4

Bar heights use a square-root scale so the small fraction places stay visible.

Signed hex numbers and two's complement

A signed hex number is negative when its top bit is 1, and computers store these negative integers in two's complement. To read the signed value, subtract 2ⁿ from the unsigned value, where n is the bit width of 8, 16, 32 or 64.

FFE6 as a signed 16-bit value
FFE6 unsigned   = 65,510
Top bit is 1    → the value is negative
65,510 − 2¹⁶    = 65,510 − 65,536
Signed value    = −26

Try FFE6 in the converter

The converter shows the signed reading of every value next to the unsigned result. Pick 8, 16, 32 or 64 bits, or leave the size on Auto to use the smallest width that fits.

Two's complement ring

Drag the marker round the ring
0−1signed

Hex to decimal in programming

Most programming languages convert hex to decimal with one built-in function, and each example below turns the string "1A2B" into 6699.

Using the value from the converter above: 0x

Python

Output:

Python

Python's int() function takes the base as its second argument and accepts the 0x prefix when the base is 16.

Python
int("1A2B", 16)      # 6699
int("0x1A2B", 16)    # 6699
0x1A2B               # 6699 (hex literal)

JavaScript

JavaScript's parseInt() takes the radix as its second argument, and BigInt() converts values above 2⁵³ − 1 without rounding.

JavaScript
parseInt("1A2B", 16)            // 6699
Number("0x1A2B")                // 6699
BigInt("0xFFFFFFFFFFFFFFFF")    // 18446744073709551615n

C and C++

The C function strtol() and the C++ function std::stoi() take the base as their third argument, and strtoul() handles unsigned values above 2,147,483,647.

C and C++
long n = strtol("1A2B", NULL, 16);        // C: 6699
int m = std::stoi("1A2B", nullptr, 16);   // C++: 6699

Java

Java's Integer.parseInt() takes the radix as its second argument, and Long.parseLong() converts values too large for an int.

Java
Integer.parseInt("1A2B", 16)      // 6699
Long.parseLong("FFFFFFFF", 16)    // 4294967295

Excel

Excel's HEX2DEC function converts up to 10 hex digits and reads values from 8000000000 to FFFFFFFFFF as negative numbers.

Excel
=HEX2DEC("1A2B")          → 6699
=HEX2DEC("FFFFFFFFFF")    → -1

How to convert decimal to hex

To convert decimal to hex, divide the number by 16 and write down the remainder, then repeat with the result until it reaches 0.

Read the remainders from last to first, and write the values 10 to 15 as the letters A to F.

6,699 in hex
6,699 ÷ 16 = 418  remainder 11 → B
418 ÷ 16 = 26  remainder 2 → 2
26 ÷ 16 = 1  remainder 10 → A
1 ÷ 16 = 0  remainder 1 → 1
Bottom to top: 1A2B

Try 6699 in the converter

Divide-by-16 ladder

Remainders read from the bottom up

    Read the remainders upward

    Frequently asked questions

    How do you convert hex to decimal?

    ▼

    To convert hex to decimal, multiply each hex digit by 16 raised to the power of its position and add the results. For example, 1A2B = 1×4,096 + 10×256 + 2×16 + 11×1 = 6,699.

    What is the formula for hex to decimal?

    ▼

    The hex to decimal formula is decimal = dₙ×16ⁿ + … + d₁×16¹ + d₀×16⁰, where d is each digit's value and n is its position from the right, starting at 0.

    What is FF in decimal?

    ▼

    FF in hex is 255 in decimal, the largest value 1 byte can hold. F equals 15, so FF = 15×16 + 15 = 255.

    What is 10 in hex to decimal?

    ▼

    Hex 10 is 16 in decimal, since the 1 sits in the 16s place and the 0 sits in the 1s place: 1×16 + 0×1 = 16.

    What are A, B, C, D, E and F in decimal?

    ▼

    A is 10, B is 11, C is 12, D is 13, E is 14 and F is 15. Hex needs these 6 letters, since base 16 has 6 more digits than base 10.

    What does 0x mean before a number?

    ▼

    0x marks a number as hexadecimal in C, Java, JavaScript, Python and most other languages. 0xFF and FF hold the same value, 255, and the converter accepts both forms.

    Is hexadecimal base 16?

    ▼

    Yes, hexadecimal is base 16, and "hex" is the short name for hexadecimal. Both names refer to the same number system, which uses 16 digits: 0 to 9 and A to F.

    How do you convert negative hex to decimal?

    ▼

    Type a minus sign before the number, and the converter turns −1A into −26. To read a two's complement value such as FFE6 as negative, set the signed size to 16 bits and read −26.

    Can hex numbers have a fractional part?

    ▼

    Yes, hex numbers can have digits after a point, and each of those digits is worth a negative power of 16. Hex 0.8 is 0.5 in decimal, and hex 1F.4 is 31.25.

    How big a number can the converter handle?

    ▼

    The converter takes up to 64 hex digits (256 bits) or 78 decimal digits. It uses exact big-integer maths, so 64-bit, 128-bit and 256-bit values convert without rounding.

    Convert a number now

    Type hex or decimal and see every digit, bit and signed value update as you type.

    Open the converter