读写二进制数

二进制数在计算机科学中扮演着核心角色,因为它基于0和1的系统来表示数据和指令。本文介绍了二进制数的基本概念,如以10为基础的写作、二进制系统的工作原理,以及如何解读二进制数列值。计算机通过将二进制数组合解释为文本和指令,比如ASCII码用于表示字母和符号。
摘要由CSDN通过智能技术生成

When you learn most types of computer programming, you touch upon the subject of binary numbers. The binary number system plays an important role in how information is stored on computers because computers only understand numbers —specifically, base 2 numbers. The binary number system is a base 2 system that uses only the numerals 0 and 1 to represent "off" and "on" in a computer's electrical system. The two binary digits 0 and 1 are used in combination to communicate text and computer processor instructions.

当您学习大多数类型的计算机编程时 ,您将涉及二进制数的主题。 二进制数字系统在计算机上如何存储信息方面起着重要作用,因为计算机只能理解数字,特别是基数2。 二进制数字系统是以2为基础的系统,该系统仅使用数字0和1来表示计算机电气系统中的“关闭”和“打开”。 组合使用两个二进制数字0和1来传递文本和计算机处理器指令。

Although the concept of binary numbers is simple once explained, reading and writing binary is not clear at first. To understand binary numbers, which use a base 2 system, first look at the more familiar system of base 10 numbers.

尽管二进制数的概念一经解释就很简单,但是起初并不清楚二进制的读写。 要了解使用2底数制的二进制数,请先看一下更熟悉的10进制数制。

以10为基础写作 ( Writing in Base 10 )

Take the three-digit number 345, for example. The farthest right number, 5, represents the 1s column, and there are 5 ones. The next number from the right, the 4, represents the 10s column. Interpret the number 4 in the 10s column as 40. The third column, which contains the 3, represents the 100s column. Many people know base 10 through education and years of exposure to numbers.

取三位数 例如345。 最右边的数字5代表1s列,共有5个。 右边的下一个数字4代表10s列。 将10s列中的数字4解释为40。包含3的第三列代表100s列。 许多人通过教育和多年接触数字来知道以10为基数。

Base 2系统 ( The Base 2 System )

Binary works in a similar way. Each column represents a value. When one column is filled, move to the next column. In a base 10 system, each column needs to reach 10 before moving to the next column. Any column can have a value of 0 through 9, but once the count goes beyond that, add a column. In base 2 or binary, each column can contain only 0 or 1 before moving to the next column.

二进制以类似的方式工作。 每列代表一个值。 填充一列后,移至下一列。 在以10为基数的系统中,每列需要达到10才能移至下一列。 任何列的值都可以是0到9,但是一旦计数超过该值,就添加一列。 在以2为底数或二进制数的情况下,每一列只能包含0或1,然后再移至下一列。

In base 2, each column represents a value that is double the previous value. The values of positions, starting on the right, are 1, 2, 4, 8, 16, 32, 64, 128, 256, 512, and so on.

基数2中 ,每列表示一个值,该值是前一个值的两倍。 从右边开始的位置值为1、2、4、8、16、32、64、128、256、512,依此类推。

The number one is represented as 1 in both base ten and binary, so let's move on to the number two. In base ten, it is represented with a 2. However, in binary, there can be only a 0 or a 1 before moving on to the next column. As a result, the number 2 is written as 10 in binary. It requires a 1 in the 2s column and 0 in the 1s column.

在十进制数和二进制数中,数字1均表示为1,因此让我们继续进行数字2。 在以10为底的数字中,它用2表示。但是,在二进制数中,前进到下一列之前只能是0或1。 结果,数字2以二进制形式写为10。 它要求在2s列中为1,在1s列中为0。

Take a look at the number three. Obviously, in base 10 it is written as 3. In base two, it is written as 11, indicating a 1 in the 2s column and a 1 in the 1s column. This becomes 2+1 = 3.

看一下数字三。 显然,在基数10中,它写为3。在基数2中,它写为11,在2s列中表示为1,在1s列中表示为1。 这变成2 + 1 = 3。

二进制数列值 ( Binary Number Column Values )

When you know how binary works, reading it is simply a matter of doing some simple math. For example:

当您知道二进制是如何工作的时,只需进行一些简单的数学运算就可以读取它。 例如:

1001: Since we know the value each of these slots represents, then we know this number represents 8 + 0 + 0 + 1. In base 10, this would be the number 9.

1001 :由于我们知道这些插槽中的每个插槽所代表的值,因此我们知道此数字表示8 + 0 + 0 +1。在10为底的情况下,该数字将为9。

11011: Calculate what this is in base 10 by adding the value of each position. In this case, this becomes 16 + 8 + 0 + 2 + 1. This is the number 27 in base 10.

11011 :通过将每个头寸的值相加来计算以10为基数的值。 在这种情况下,它变为16 + 8 + 0 + 2 +1。这是以10为底的数字27。

计算机中的数字 ( Numbers at Work in a Computer )

So, what does all this mean to the computer? The computer interprets combinations of binary numbers as text or instructions. For example, each lowercase and uppercase letter of the alphabet is assigned a different binary code. Each is also assigned a decimal representation of that code, called an ASCII code. For example, the lowercase "a" is assigned the binary number 01100001. It is also represented by the ASCII code 097. If you do the math on the binary number, you'll see it equals 97 in base 10. 

那么,这对计算机意味着什么? 计算机将二进制数字的组合解释为文本或指令。 例如,字母表的每个小写和大写字母都分配有不同的二进制代码。 还为每个代码分配了该代码的十进制表示形式,称为ASCII代码 。 例如,小写的“ a”被分配了二进制数字01100001。它也由ASCII码097表示。如果对二进制数字进行数学运算,您将在基数10中看到它等于97。

翻译自: https://www.thoughtco.com/what-is-binary-2694150

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值