十进制转二进制转换器

这个十进制转二进制转换器使用反复除法将十进制(基数 10)数转换为二进制(基数 2)表示。输入任意十进制数,即可查看对应的二进制结果及逐步分解说明,同时提供八进制和十六进制转换,支持 8 位、16 位、32 位固定宽度格式及负数的补码表示。

Decimal to Binary Converter

Convert between decimal and binary number systems with step-by-step division

Frequently Asked Questions

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

将十进制数转换为二进制时,反复将数字除以2并记录每步的余数。继续直到商为0。然后从下到上(从最后到第一个)读取余数,得到二进制数。例如,转换13:13/2=6余1,6/2=3余0,3/2=1余1,1/2=0余1。从下到上读取得1101。

什么是二进制?

二进制是一种以2为基数的数字系统,只使用两个数字:0和1。每个数字位置代表2的幂次,就像十进制(基数10)中每个位置代表10的幂次一样。二进制是数字计算机的原生语言,因为电子电路有两种状态:开(1)和关(0)。计算机中的所有数据——文本、图像、音频、视频——最终都以二进制形式表示。

什么是补码?

补码是计算机用来以二进制表示负整数的标准方法。求一个数的补码:(1)用二进制写出正值,(2)反转所有位(将0变为1,将1变为0),(3)将结果加1。例如,8位补码表示-5:从00000101开始,反转得11111010,加1得11111011。最高有效位作为符号位(0=正,1=负)。

8位二进制数的范围是什么?

对于无符号8位二进制数,范围是0到255(00000000到11111111)。对于使用补码的有符号8位数,范围是-128到127(10000000到01111111)。最大无符号值为2⁸-1=255,而有符号范围使用一位作为符号,给出-2⁷到2⁷-1。

如何用二进制表示负数?

现代计算机使用补码表示负数。最高有效位(最左边)是符号位:0表示正数,1表示负数。要取一个数的负数,反转所有位并加1。例如,8位二进制中-1是11111111,-128是10000000,-42是11010110。这种系统允许加法和减法使用相同的硬件电路。

为什么计算机使用二进制?

计算机使用二进制,因为数字电子电路有两种稳定状态:高电压(1)和低电压(0)。这种两态系统极其可靠、快速,且易于用晶体管实现。虽然人类因为有10根手指而觉得十进制(基数10)直观,但计算机天然地使用二进制(基数2)。像八进制(8)和十六进制(16)这样的更高基数用作简写,因为它们与二进制位组整洁对应。

8位、16位和32位有什么区别?

位宽决定了用多少个二进制数字来表示一个数。8位(1字节)可以表示256个值(无符号0-255,有符号-128到127)。16位(2字节)可以表示65,536个值(无符号0-65535)。32位(4字节)可以表示超过40亿个值(无符号0到4,294,967,295)。更大的位宽允许更大的数字,但占用更多内存。

如何在Python或JavaScript中将十进制转换为二进制?

在Python中,使用bin(42)得到"0b101010",或format(42, "b")得到不带前缀的"101010"。在JavaScript中,使用(42).toString(2)得到"101010"。反向转换:Python使用int("101010", 2)=42,JavaScript使用parseInt("101010", 2)=42。两种语言都支持带0b前缀的二进制字面量:0b101010等于42。

常见十进制数的二进制是什么?

常见转换:0=0、1=1、2=10、5=101、10=1010、16=10000、32=100000、42=101010、64=1000000、100=1100100、128=10000000、255=11111111、256=100000000、1000=1111101000、1024=10000000000。2的幂次始终只有一个"1"位后面跟着零。

二进制与十六进制有什么关系?

十六进制(基数16)是二进制的紧凑表示。每个十六进制数字精确映射到4个二进制位:0=0000、1=0001、...、9=1001、A=1010、B=1011、C=1100、D=1101、E=1110、F=1111。所以十六进制FF等于二进制11111111(十进制255),0x2A等于二进制00101010(十进制42)。这种4位对齐使十六进制成为表示字节值的理想选择。

About Decimal to Binary Converter

The Decimal to Binary Converter transforms base-10 decimal numbers into base-2 binary representation, the fundamental number system used by all digital computers. Every piece of data a computer processes — text, images, audio, video, and instructions — is ultimately stored and manipulated as sequences of binary digits (bits), where each bit is either 0 or 1.

This tool converts any non-negative integer to binary instantly and shows the step-by-step division method so you can follow the conversion process. It also displays the octal (base-8) and hexadecimal (base-16) equivalents, supports fixed-width formats (8-bit, 16-bit, 32-bit), and handles negative numbers using two's complement representation.

How to Convert Decimal to Binary

The standard method for converting a decimal integer to binary is the repeated division by 2 algorithm. You divide the number by 2 repeatedly, recording the remainder at each step, until the quotient reaches 0. The binary result is the sequence of remainders read from bottom to top (last remainder first).

Example: Convert 42 to Binary

Decimal input: 42

1. 42 ÷ 2 = 21, remainder 0

2. 21 ÷ 2 = 10, remainder 1

3. 10 ÷ 2 = 5, remainder 0

4. 5 ÷ 2 = 2, remainder 1

5. 2 ÷ 2 = 1, remainder 0

6. 1 ÷ 2 = 0, remainder 1

Read remainders bottom to top: 101010

Therefore, decimal 42 = binary 101010.

Example: Convert 255 to Binary

Decimal input: 255

1. 255 ÷ 2 = 127, remainder 1

2. 127 ÷ 2 = 63, remainder 1

3. 63 ÷ 2 = 31, remainder 1

4. 31 ÷ 2 = 15, remainder 1

5. 15 ÷ 2 = 7, remainder 1

6. 7 ÷ 2 = 3, remainder 1

7. 3 ÷ 2 = 1, remainder 1

8. 1 ÷ 2 = 0, remainder 1

Read remainders bottom to top: 11111111

Decimal 255 = binary 11111111 (8 bits, all ones). This is the maximum value of a single unsigned byte.

General Formula:

Repeat: quotient = floor(N / 2), remainder = N mod 2, then N = quotient, until N = 0.

The binary number is the remainders read in reverse order (bottom to top).

Two's Complement Explained

Two's complement is the standard method used by computers to represent signed integers (positive and negative numbers). The most significant bit (MSB) serves as the sign bit: 0 for positive, 1 for negative. The remaining bits encode the magnitude.

How to Find Two's Complement

To represent -5 in 8-bit two's complement:

1. Start with the binary of 5: 00000101

2. Invert all bits: 11111010

3. Add 1: 11111011

Result: -5 in 8-bit two's complement = 11111011

Two's Complement Ranges

BitsSigned RangeUnsigned Range
8-128 to 1270 to 255
16-32,768 to 32,7670 to 65,535
32-2,147,483,648 to 2,147,483,6470 to 4,294,967,295

Two's complement has a key advantage: addition and subtraction work the same way for both positive and negative numbers, simplifying CPU hardware design. This is why virtually every modern processor uses it.

Common Conversions Table (0-31)

Here are the first 32 decimal values and their binary, hexadecimal, and octal equivalents:

DecimalBinaryHexOctal
000000000000
100000001011
200000010022
300000011033
400000100044
500000101055
600000110066
700000111077
8000010000810
9000010010911
10000010100A12
11000010110B13
12000011000C14
13000011010D15
14000011100E16
15000011110F17
16000100001020
17000100011121
18000100101222
19000100111323
20000101001424
21000101011525
22000101101626
23000101111727
24000110001830
25000110011931
26000110101A32
27000110111B33
28000111001C34
29000111011D35
30000111101E36
31000111111F37

Applications

  • Computing & Programming: Understanding how integers, characters, and data are stored in memory at the binary level. Bitwise operations, bit masking, and flag manipulation all require decimal-to-binary fluency.
  • Networking: IP addresses and subnet masks are 32-bit binary numbers. Converting between decimal dotted-notation (e.g., 192.168.1.0) and binary is essential for subnetting and network design.
  • Digital Electronics: Logic gates, flip-flops, registers, and bus architectures all operate on binary signals. Engineers routinely convert between decimal specifications and binary representations.
  • Data Storage: File sizes, memory addresses, and disk sectors are measured in powers of 2. Understanding binary helps explain why a "1 GB" drive holds 1,073,741,824 bytes (230).
  • Cryptography: Encryption algorithms, hash functions, and key generation operate on binary data. Understanding binary representation is fundamental to cryptographic analysis and our Vernam cipher tool.
  • Education: Learning decimal-to-binary conversion builds foundational understanding of how computers work, making it a core topic in computer science curricula.

Related Tools