十六进制转二进制转换器

这个十六进制转二进制转换器可将十六进制(基数 16)数转换为二进制(基数 2)表示。输入任意十六进制数,即可查看对应的二进制结果,并附有每个十六进制数字到 4 位二进制组的映射分解说明。

Hex to Binary Converter

Convert hexadecimal numbers to their binary representation

Frequently Asked Questions

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

将每个十六进制数字替换为其对应的4位二进制值。映射关系为:0=0000、1=0001、2=0010、...、9=1001、A=1010、B=1011、C=1100、D=1101、E=1110、F=1111。例如,十六进制2F转换时将2替换为0010,将F替换为1111,得到00101111。这种直接替换有效,因为每个十六进制数字精确代表4个二进制位(因为16=2⁴)。

什么是十六进制?

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

为什么每个十六进制数字等于4个二进制位?

每个十六进制数字等于4个二进制位,因为16=2⁴。一个十六进制数字可以表示0-15的值,这恰好是4个二进制位的范围(0000到1111)。这种完美的2的幂次关系意味着十六进制和二进制之间的转换只是简单的直接替换,无需任何算术。这就是为什么十六进制成为计算中二进制的首选简写,而不是十进制或八进制。

0xFF在二进制中是什么?

0xFF在二进制中是11111111(八个1)。0x前缀表示十六进制数。十六进制中的F等于十进制15,即二进制1111。由于FF有两个十六进制数字,每个转换为4位,结果是1111 1111=11111111。这等于十进制255,代表无符号8位字节的最大值。0xFF通常在编程中用作位掩码,以隔离单个字节。

十六进制用于哪些场景?

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

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

将二进制数从右侧开始分成每4位一组。如果需要,用前导零填充最左边的组。然后将每个4位组替换为对应的十六进制:0000=0、0001=1、...、1001=9、1010=A、1011=B、1100=C、1101=D、1110=E、1111=F。例如,二进制11010110分组为1101 0110,转换为十六进制D6。

十六进制数字A到F是什么?

十六进制数字A到F代表十进制值10到15:A=10(二进制1010)、B=11(1011)、C=12(1100)、D=13(1101)、E=14(1110)、F=15(1111)。使用字母是因为每个十六进制位置必须代表16个可能的值(0-15),这超出了十个可用的十进制数字。大写(A-F)和小写(a-f)在大多数场景下都可以接受,但大写是惯例。

如何将二进制转换回十六进制?

从右到左将二进制数字分成每4位一组,然后将每组转换为对应的十六进制。例如,10110010变为1011 0010,即十六进制B2。

How to Convert Hex to Binary

Converting hexadecimal to binary is one of the most straightforward base conversions in computing. Because hexadecimal is base-16 and binary is base-2, and because 16 is a perfect power of 2 (16 = 24), every single hex digit maps directly to exactly 4 binary bits. No arithmetic is needed — just a simple lookup and substitution.

Step-by-Step Conversion Method

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

Step 1: Write down the hex number

Remove any prefix such as 0x or #. For example, 0x2F becomes 2F.

Step 2: Replace each hex digit with its 4-bit binary equivalent

Use the mapping table: 0=0000, 1=0001, 2=0010, 3=0011, 4=0100, 5=0101, 6=0110, 7=0111, 8=1000, 9=1001, A=1010, B=1011, C=1100, D=1101, E=1110, F=1111.

Step 3: Combine all 4-bit groups

Concatenate the binary groups from left to right. The result is the full binary representation.

Why Each Hex Digit Equals 4 Binary Bits

The mathematical relationship is simple: a single hexadecimal digit can represent values from 0 to 15, which is exactly the range of 4 binary bits (24=162^4 = 16). This means:

(d)16=(b3b2b1b0)2where d{0,1,...,F}(d)_{16} = (b_3 b_2 b_1 b_0)_2 \quad \text{where } d \in \{0,1,...,F\}

Each hex digit dd maps to exactly one 4-bit binary nibble. This perfect power-of-2 relationship is why hexadecimal became the preferred shorthand for binary data in computing, rather than decimal or octal.

Two hex digits represent one byte (8 bits), four hex digits represent a 16-bit word, and eight hex digits represent a 32-bit word. This clean alignment makes hex-to-binary conversion trivially mechanical.

Hex to Binary Conversion Examples

Below are worked examples showing the hex to binary conversion process step by step, from simple single-byte values to multi-byte color codes.

Convert 2F to Binary

Hex input: 2F

1. 216=(0010)22_{16} = (0010)_2

2. F16=(1111)2F_{16} = (1111)_2

3. 2F16=(0010  1111)22F_{16} = (0010\;1111)_2

Decimal equivalent: 47

Convert 4FA to Binary

Hex input: 4FA

1. 416=(0100)24_{16} = (0100)_2

2. F16=(1111)2F_{16} = (1111)_2

3. A16=(1010)2A_{16} = (1010)_2

4. 4FA16=(0100  1111  1010)24FA_{16} = (0100\;1111\;1010)_2

Decimal equivalent: 1,274

Convert FF to Binary

Hex input: FF

1. F16=(1111)2F_{16} = (1111)_2

2. F16=(1111)2F_{16} = (1111)_2

3. FF16=(1111  1111)2FF_{16} = (1111\;1111)_2

Decimal equivalent: 255 — the maximum value of a single unsigned byte (8 bits all set to 1).

Convert Color Code #3A7BD5 to Binary

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

1. 316=(0011)23_{16} = (0011)_2

2. A16=(1010)2A_{16} = (1010)_2

3. 716=(0111)27_{16} = (0111)_2

4. B16=(1011)2B_{16} = (1011)_2

5. D16=(1101)2D_{16} = (1101)_2

6. 516=(0101)25_{16} = (0101)_2

7. 3A7BD516=(0011  1010  0111  1011  1101  0101)23A7BD5_{16} = (0011\;1010\;0111\;1011\;1101\;0101)_2

The 24-bit result breaks into three bytes: R=00111010 (58), G=01111011 (123), B=11010101 (213). You can also convert hex color codes using our hex to RGB converter.

Hex to Binary Conversion Table

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

Quick Reference (Single Hex Digits 0-F):

HexDecimalBinary
00000000000
01100000001
02200000010
03300000011
04400000100
05500000101
06600000110
07700000111
08800001000
09900001001
0A1000001010
0B1100001011
0C1200001100
0D1300001101
0E1400001110
0F1500001111

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

Hex to Binary in Programming

Most programming languages provide built-in functions for converting between hexadecimal and binary. Here are examples in the three most popular languages.

Python

# Convert hex string to binary string
hex_value = "FF"
binary_value = bin(int(hex_value, 16))
print(binary_value)          # '0b11111111'

# Remove '0b' prefix and pad to 8 bits
binary_clean = bin(int(hex_value, 16))[2:].zfill(8)
print(binary_clean)          # '11111111'

# Format with 4-bit groups
hex_value = "3A7BD5"
binary_str = bin(int(hex_value, 16))[2:].zfill(len(hex_value) * 4)
grouped = ' '.join([binary_str[i:i+4] for i in range(0, len(binary_str), 4)])
print(grouped)               # '0011 1010 0111 1011 1101 0101'

JavaScript

// Convert hex string to binary string
const hexValue = "FF";
const binaryValue = parseInt(hexValue, 16).toString(2);
console.log(binaryValue);    // '11111111'

// Pad to 8 bits
const padded = binaryValue.padStart(8, '0');
console.log(padded);         // '11111111'

// For large hex values, use BigInt
const bigHex = "3A7BD5";
const bigBin = BigInt("0x" + bigHex).toString(2).padStart(bigHex.length * 4, '0');
console.log(bigBin);         // '001110100111101111010101'

Java

// Convert hex string to binary string
String hexValue = "FF";
String binaryValue = Integer.toBinaryString(Integer.parseInt(hexValue, 16));
System.out.println(binaryValue);  // "11111111"

// Pad to 8 bits
String padded = String.format("%8s", binaryValue).replace(' ', '0');
System.out.println(padded);       // "11111111"

// For larger values, use Long
String bigHex = "3A7BD5";
String bigBin = Long.toBinaryString(Long.parseLong(bigHex, 16));
System.out.println(bigBin);       // "1110100111101111010101"

Key Features

  • Instant hex to binary conversion with real-time validation
  • Comprehensive hex to binary conversion process visualization
  • Clear error messages for invalid hexadecimal inputs
  • Optional digit grouping for enhanced binary number readability
  • Support for converting any length of hexadecimal numbers to binary
  • Automatic decimal equivalent display with smart formatting
  • Step-by-step hex to binary conversion breakdown

Applications

  • Digital circuit design and analysis requiring hex to binary conversions
  • Computer memory debugging using hex to binary representation
  • Binary data manipulation in programming with hex to binary conversion
  • Assembly language programming and machine code analysis
  • Educational purposes for understanding hex to binary number systems
  • Color code conversions in web development (e.g., hex to RGB)

Related Converters

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

For a deep dive into the theory and practice of hex-to-binary conversion, read our comprehensive guide: Hex to Binary Conversion: Complete Guide with Table & Examples.