首页 > 编程知识 正文

c 十六进制转二进制数二进制数制,十六进制数十

时间:2023-05-05 06:39:50 阅读:211227 作者:3440

c++ 十六进制转二进制数

I recently introduced the Decimal Number System, the one we are used as humans.

我最近介绍了小数系统 ,即我们用作人类的系统。

As I said in that post, as humans we commonly have 10 fingers and we can count up to 10, hence the popularity of that system in our history.

就像我在那篇文章中所说的那样,作为人类,我们通常有10个手指,我们最多可以数10个手指,因此该系统在我们的历史中非常流行。

The Binary Number System is the second most important system for our species, as it led the electronics and computer revolution.

二进制数系统是对我们物种而言第二重要的系统,因为它引领了电子和计算机革命。

In electronics, we have 2 states: 0 or 1. There’s 0 volts, or there’s 5 (or 9, 12, whatever). A gate is open, or it’s closed.

在电子领域,我们有2种状态:0或1。有0伏,或者有5伏(或9、12,无论如何)。 门是打开的还是关闭的。

It’s either one or the another.

这是一个或另一个。

The digit in the binary number system is called bit.

二进制数字系统中的数字称为bit

As the decimal number system, also the binary number system is positional.

作为十进制数字系统,二进制数字系统也是positional

We sum each digit in the binary number system mutiplied by the power of 2 depending on their position, starting at position 0 from the right.

我们将二进制数字系统中的每个数字相加,并乘以2的幂,具体取决于它们的位置,从右边的位置0开始。

Given that:

鉴于:

[2^0] equals to 1

[2 ^ 0 ]等于1

[2^1] equals to 2

[2 ^ 1 ]等于2

[2^2] equals to 4

[2 ^ 2 ]等于4

[2^3] equals to 8, and so on..

[2 ^ 3 ]等于8,依此类推。

We can represent numbers using a series of bits:

我们可以使用一系列位来表示数字:

1 can be represented as [1times2^0]

1可以表示为 [1 times2 ^ 0 ]

10 can be represented as [1times2^1 + 0times2^0]

10可以表示为 [1 times2 ^ 1 + 0 times2 ^ 0 ]

111 can be represented as [1times2^2 + 1times2^1 + 1times2^0]

111可以表示为 [1 times2 ^ 2 +1 times2 ^ 1 +1 times2 ^ 0 ]

Leading zeros in a number can be dropped, or added if needed, because they do not mean anything on the left of the top left 1: 110 can be represented a 0110 or 00000110 if needed. It holds the same exact meaning, because as the system above explained, we are simply multiplying a power of 2 times zero.

可以删除或添加数字中的前导零,因为它们并不意味着左上角1 : 110都可以表示0110或00000110如果需要)。 它具有相同的确切含义,因为正如上面的系统所解释的,我们只需将2的幂乘以零即可。

Using binary numbers we can represent any kind of number in the decimal number system.

使用二进制数字,我们可以表示十进制数字系统中的任何类型的数字。

We need to have an adequate number of digits to represent enough numbers. If we want to have 16 numbers, so we can count from 0 to 15, we need 4 digits (bits). With 5 bits we can count 32 numbers. 32 bits will give us 4,294,967,296 possible numbers.

我们需要有足够的数字来表示足够的数字。 如果我们要有16个数字,那么我们可以从0到15进行计数,我们需要4个数字(位)。 使用5位,我们可以计算32个数字。 32位将给我们4,294,967,296可能的数字。

64 bits will give us 9,223,372,036,854,775,807 possible numbers. It grows pretty quickly.

64位将为我们提供9,223,372,036,854,775,807可能的数字。 它增长很快。

Here is a simple conversion table for the first 4 digits, which we can generate using just 2 bits:

这是前4位的简单转换表,我们只需使用2位就可以生成:

Decimal numberBinary number000101210311 小数 二进制数 0 00 1个 01 2 10 3 11

Here is a simple conversion table for the first 8 digits:

这是前8位数字的简单转换表:

Decimal numberBinary number00001001201030114100510161107111 小数 二进制数 0 000 1个 001 2 010 3 011 4 100 5 101 6 110 7 111

If you notice, I repeated the above sequence, adding 1 instead of 0 in the series from 4 to 7.

如果您注意到,我重复了上述顺序,在从4到7的序列中加了1而不是0 。

Here is a simple conversion table for the first 16 digits:

这是前16位的简单转换表:

Decimal numberBinary number00000100012001030011401005010160110701118100091001101010111011121100131101141110151111 小数 二进制数 0 0000 1个 0001 2 0010 3 0011 4 0100 5 0101 6 0110 7 0111 8 1000 9 1001 10 1010 11 1011 12 1100 13 1101 14 1110 15 1111

Again, I repeated the sequence we used to get the first 8 numbers, prepended 0 to the first set 0-7 and prepended 1 to 8-15.

再次,我重复了我们用来获得前8个数字的顺序,将0附加到第一个数字0-7之前,将1附加到8-15。

I’ll soon talk about performing operations like sum and division with binary numbers, the hexadecimal numbers system, how to convert from binary to decimal and to hexadecimal, without looking at tables like these, and vice versa.

我将很快讨论如何执行诸如用二进制数求和和除法,十六进制数系统,如何从二进制转换为十进制以及转换为十六进制的操作,而无需查看此类表,反之亦然。

翻译自: https://flaviocopes.com/binary-number-system/

c++ 十六进制转二进制数

版权声明:该文观点仅代表作者本人。处理文章:请发送邮件至 三1五14八八95#扣扣.com 举报,一经查实,本站将立刻删除。