十六进制转十进制转换器

这个十六进制转十进制转换器可将十六进制(基数 16)数转换为十进制(基数 10)表示。输入任意十六进制数,即可查看其十进制等值,并附有逐步位置值分解说明,同时提供反向十进制转十六进制功能。

Hex to Decimal Converter

Convert between hexadecimal and decimal number systems

Frequently Asked Questions

如何将十六进制转换为十进制?

将每个十六进制数字乘以其位置对应的16的幂次,然后求和。写出十六进制数,从右到左从16⁰开始分配16的幂次,将A-F等字母转换为对应的十进制值(A=10、B=11、C=12、D=13、E=14、F=15),将每个数字乘以其16的幂次,然后将所有乘积相加。例如,十六进制2F = 2×16¹ + 15×16⁰ = 32 + 15 = 47。

什么是十六进制?

十六进制(hex)是一种以16为基数的数字系统,使用十六个符号:0-9表示0到9的值,A-F表示10到15的值。它广泛用于计算,因为每个十六进制数字精确代表4个二进制位,提供了一种紧凑且便于人类阅读的表示二进制数据的方式。两个十六进制数字代表一个字节(8位),所以二进制中像11111111这样的字节值在十六进制中可以简单地写为FF。

十六进制到十进制的公式是什么?

十六进制到十进制的公式为:十进制 = d(n)×16ⁿ + d(n-1)×16^(n-1) + ... + d(1)×16¹ + d(0)×16⁰,其中d(i)是位置i(从右侧0开始计数)处十六进制数字的十进制值。十六进制A-F在乘以对应的16的幂次之前,先替换为其十进制等值(A=10到F=15)。

如何快速将十六进制转换为十进制?

对于小的十六进制值,记住每个十六进制数字位置的值依次为1、16、256、4096等。对于两位十六进制数如"AB",计算:A(10)×16 + B(11) = 160 + 11 = 171。对于单个十六进制数字0-F,十进制值就是数字本身(0-9)或字母的值(A=10到F=15)。对于较大的值,使用我们免费的十六进制转十进制转换器立即获得结果。

0xFF的十进制是什么?

0xFF的十进制是255。0x前缀表示十六进制数。十六进制中的F等于十进制15,所以FF = 15×16 + 15 = 240 + 15 = 255。这是无符号8位字节的最大值(二进制中所有8位都设为1:11111111)。0xFF通常在编程中用作位掩码,以从较大的值中隔离单个字节。

如何将有符号十六进制转换为十进制?

对于有符号十六进制(补码),检查最高有效位是否被设置。对于8位值,如果十六进制为80-FF,则数字为负数。求负值:反转所有位并加1。例如,十六进制FF作为有符号8位整数:FF=二进制11111111,反转得00000000,加1得00000001=1,所以结果是-1。十六进制7F(01111111)是最大正有符号字节值:127。

十六进制和十进制有什么区别?

十六进制是基数16(使用数字0-9和字母A-F),而十进制是基数10(只使用数字0-9)。十六进制在计算中更受欢迎,因为它与二进制完美对齐:每个十六进制数字精确代表4位。这使十六进制成为二进制数据的紧凑表示——二进制中的字节值11010110在十六进制中是D6,但在十进制中是214。十进制是日常数学中使用的标准人类数字系统。

十六进制在计算中用于哪些场景?

十六进制在计算中被广泛使用:Web设计中的颜色代码(#FF5733)、调试中的内存地址(0x7FFF5FBFF8AC)、网络中的MAC地址(00:1A:2B:3C:4D:5E)、Unicode字符代码(字母A的U+0041)、加密哈希(SHA-256产生64个十六进制数字)、汇编语言编程和IPv6地址。它受到偏爱,因为两个十六进制数字精确代表一个字节。

如何在Python中将十六进制转换为十进制?

在Python中,使用内置的int()函数配合基数16:int("FF", 16)返回255。也可以使用0x前缀的十六进制字面量:0xFF等于255。反向转换(十进制到十六进制),使用hex(255)返回"0xff",或format(255, "X")得到不带前缀的大写:"FF"。

0x前缀是什么意思?

0x前缀是C、Java、Python和JavaScript等编程语言中使用的约定,表示数字是十六进制(基数16)。例如,0xFF表示十六进制值FF(十进制255),而不是字符串"FF"。其他常见的十六进制表示法包括:CSS颜色代码中的#(#FF5733)、某些汇编语言中的$,以及Intel汇编中的h后缀(FFh)。前缀不改变值——它只是告诉解析器将数字解释为十六进制。

How to Convert Hex to Decimal

Converting hexadecimal to decimal uses positional notation — the same principle behind how decimal numbers work, but with base 16 instead of base 10. Each digit in a hex number has a positional value that is a power of 16, and the decimal result is the sum of all digit values multiplied by their positional weights.

The Positional Notation Formula

The general formula for converting a hex number with nn digits to decimal is:

D=dn1×16n1+dn2×16n2++d1×161+d0×160D = d_{n-1} \times 16^{n-1} + d_{n-2} \times 16^{n-2} + \cdots + d_1 \times 16^1 + d_0 \times 16^0

Where did_i is the decimal value of the hex digit at position ii (counting from the right, starting at 0). Hex letters map to: A=10, B=11, C=12, D=13, E=14, F=15.

Step-by-Step Conversion Method

Follow these steps to convert any hexadecimal number to decimal by hand:

Step 1: Write down the hex number

Remove any prefix such as 0x or #. For example, 0x1A3F becomes 1A3F.

Step 2: Assign powers of 16 to each digit from right to left

The rightmost digit gets 160 = 1, the next gets 161 = 16, then 162 = 256, 163 = 4,096, and so on.

Step 3: Convert hex letters (A-F) to their decimal values

Replace A with 10, B with 11, C with 12, D with 13, E with 14, and F with 15. Digits 0-9 remain unchanged.

Step 4: Multiply each digit by its power of 16

Calculate the product of each digit's decimal value and its corresponding power of 16.

Step 5: Sum all products

Add all the products together. The result is the decimal equivalent of the hexadecimal number.

Powers of 16 Reference

Memorizing the first few powers of 16 makes hex-to-decimal conversion much faster:

PowerValueMeaning
1601Ones place
16116Sixteens place
162256Two-fifty-sixes place
1634,096Four-thousand-ninety-sixes place
16465,53616-bit boundary
1684,294,967,29632-bit boundary

Hex to Decimal Conversion Table

This complete hex to decimal conversion table covers all 256 byte values from 00 to FF. Each row shows the hexadecimal value, its decimal equivalent, binary representation, and octal equivalent.

Quick Reference (Single Hex Digits 0-F):

HexDecimalBinaryOctal
00000000000000
01100000001001
02200000010002
03300000011003
04400000100004
05500000101005
06600000110006
07700000111007
08800001000010
09900001001011
0A1000001010012
0B1100001011013
0C1200001100014
0D1300001101015
0E1400001110016
0F1500001111017

This table covers all possible single-byte hexadecimal values (00-FF) with their decimal, 8-bit binary, and octal equivalents. For values beyond FF, apply the same positional notation formula to each hex digit.

Hex to Decimal Conversion Examples

Below are worked examples showing the hex to decimal conversion process step by step, from simple single-digit values to multi-byte numbers.

Convert 2F to Decimal

Hex input: 2F

1. 2×161=2×16=322 \times 16^1 = 2 \times 16 = 32

2. F(15)×160=15×1=15F(15) \times 16^0 = 15 \times 1 = 15

3. 32+15=4732 + 15 = 47

Result: 2F16 = 4710

Convert FF to Decimal

Hex input: FF

1. F(15)×161=15×16=240F(15) \times 16^1 = 15 \times 16 = 240

2. F(15)×160=15×1=15F(15) \times 16^0 = 15 \times 1 = 15

3. 240+15=255240 + 15 = 255

Result: FF16 = 25510 — the maximum value of an unsigned byte.

Convert 1A3F to Decimal

Hex input: 1A3F

1. 1×163=1×4096=40961 \times 16^3 = 1 \times 4096 = 4096

2. A(10)×162=10×256=2560A(10) \times 16^2 = 10 \times 256 = 2560

3. 3×161=3×16=483 \times 16^1 = 3 \times 16 = 48

4. F(15)×160=15×1=15F(15) \times 16^0 = 15 \times 1 = 15

5. 4096+2560+48+15=67194096 + 2560 + 48 + 15 = 6719

Result: 1A3F16 = 6,71910

Convert DEADBEEF to Decimal

Hex input: DEADBEEF (a famous "hexspeak" debug marker)

1. D(13)×167=13×268435456=3,489,660,928D(13) \times 16^7 = 13 \times 268435456 = 3{,}489{,}660{,}928

2. E(14)×166=14×16777216=234,881,024E(14) \times 16^6 = 14 \times 16777216 = 234{,}881{,}024

3. A(10)×165=10×1048576=10,485,760A(10) \times 16^5 = 10 \times 1048576 = 10{,}485{,}760

4. D(13)×164=13×65536=851,968D(13) \times 16^4 = 13 \times 65536 = 851{,}968

5. B(11)×163=11×4096=45,056B(11) \times 16^3 = 11 \times 4096 = 45{,}056

6. E(14)×162=14×256=3,584E(14) \times 16^2 = 14 \times 256 = 3{,}584

7. E(14)×161=14×16=224E(14) \times 16^1 = 14 \times 16 = 224

8. F(15)×160=15×1=15F(15) \times 16^0 = 15 \times 1 = 15

Result: DEADBEEF16 = 3,735,928,55910 — a 32-bit value commonly used to mark uninitialized memory.

Convert Color Code #3A7BD5 to Decimal

Hex input: #3A7BD5 (a shade of blue)

Full value: 3A7BD516=3,833,813103A7BD5_{16} = 3{,}833{,}813_{10}

Per channel (each pair is one byte):

Red: 3A16=3×16+10=583A_{16} = 3 \times 16 + 10 = 58

Green: 7B16=7×16+11=1237B_{16} = 7 \times 16 + 11 = 123

Blue: D516=13×16+5=213D5_{16} = 13 \times 16 + 5 = 213

RGB result: (58, 123, 213). You can also convert hex color codes using our hex to RGB converter.

Hex to Decimal in Programming

Most programming languages provide built-in functions for converting hexadecimal strings to decimal integers. Here are examples in popular languages.

Python

# Convert hex string to decimal integer
hex_value = "FF"
decimal_value = int(hex_value, 16)
print(decimal_value)          # 255

# Using 0x prefix literal
value = 0xFF
print(value)                  # 255

# Decimal to hex (reverse)
print(hex(255))               # '0xff'
print(format(255, 'X'))       # 'FF'

# Large hex values
big_hex = "DEADBEEF"
big_decimal = int(big_hex, 16)
print(big_decimal)            # 3735928559

JavaScript

// Convert hex string to decimal number
const hexValue = "FF";
const decimalValue = parseInt(hexValue, 16);
console.log(decimalValue);    // 255

// Using 0x prefix literal
const value = 0xFF;
console.log(value);           // 255

// Decimal to hex (reverse)
console.log((255).toString(16).toUpperCase()); // 'FF'

// For values larger than 2^53, use BigInt
const bigHex = "DEADBEEFDEADBEEF";
const bigDec = BigInt("0x" + bigHex);
console.log(bigDec.toString()); // '16045690984833335023'

C

#include <stdio.h>
#include <stdlib.h>

int main() {
    // Convert hex string to decimal using strtol
    const char *hexStr = "FF";
    long decimal = strtol(hexStr, NULL, 16);
    printf("%ld\n", decimal);  // 255

    // Using hex literal
    int value = 0xFF;
    printf("%d\n", value);     // 255

    // Larger value
    unsigned long big = strtoul("DEADBEEF", NULL, 16);
    printf("%lu\n", big);      // 3735928559

    return 0;
}

Applications of Hex to Decimal Conversion

  • Memory addresses — Debugging tools display memory addresses in hex (e.g., 0x7FFF5FBFF8AC). Converting to decimal helps with offset calculations and pointer arithmetic.
  • Web color codes — CSS hex colors like #FF5733 encode RGB channel values as decimal 0-255. Converting hex pairs to decimal reveals the actual color intensity: FF = 255 (max red), 57 = 87 (moderate green), 33 = 51 (low blue).
  • MAC addresses — Network interface identifiers (00:1A:2B:3C:4D:5E) use hex notation. Converting to decimal is needed for certain network administration tasks and database queries.
  • Unicode code points — Characters are identified by hex code points (e.g., U+0041 for the letter "A"). Converting U+0041 to decimal gives 65, which is the ASCII value.
  • Cryptographic hashes — Hash values like SHA-256 are displayed in hex. Converting individual bytes to decimal is useful for checksum verification and statistical analysis.

Related Converters

Explore our other number system and encoding converters for related tasks:

For a deep dive into how hexadecimal works and its role in computing, read our comprehensive guide: How Does Hexadecimal Work: Complete Guide to Base-16 Numbers.