数字系统设计_数字系统

数字系统设计

Decimal, Binary, Octal, and Hexadecimal

十进制,二进制,八进制和十六进制

While studying JavaScript I became curious about numeral systems when using the parseInt( ) function. The parseInt( ) function is used to parse a string into an integer. This function accepts two arguments, the first argument is the string you want to parse, and the second argument is the radix.

在学习JavaScript时,我对使用parseInt()函数的数字系统感到好奇。 parseInt()函数用于将字符串解析为整数。 此函数接受两个参数,第一个参数是要解析的字符串,第二个参数是radix

Image for post

The radix or base is the number of unique digits used to represent numbers in a positional numeral system. The radix in the parseInt( ) function can be any number 2–36 and does not default to base 10. Let’s explore a few of the counting systems that we use today.

基数基数是用于表示位置数字系统中数字的唯一数字的数量。 parseInt()函数中的基数可以是2到36之间的任何数字,并且默认不以10为底。让我们探究一些我们今天使用的计数系统。

十进制或十进制 (Decimal System or Base 10)

Unique Digits = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9

唯一数字 = 0、1、2、3、4、5、6、7、8、9

Base 10 is the counting system that most of us are used to working with so we will start there. The radix/base number is 10 because it uses 10 digits. Let’s look at the number 974,210. In the example below the 0 is in the “one’s position”, the 1 is in the “ten’s position”, the 2 is in the “hundred’s position”, the 4 is in the “thousand’s position” and so on. Each number is worth ten times more than the digit to the right.

Base 10是我们大多数人都习惯使用的计数系统,因此我们将从这里开始。 基数/基数为10,因为它使用10位数字。 让我们看看数字974,210。 在下面的示例中,0处于“一个人的位置”,1处于“十人的位置”,2处于“百人的位置”,4处于“千人的位置”,依此类推。 每个数字的价值是右边数字的十倍。

Image for post

Fun fact: Many ancient civilizations used base 10 to represent numbers. It is rumored that this is due to humans starting to count using their 10 fingers.

有趣的事实:许多古代文明都使用10为基数来表示数字。 据传这是由于人类开始用十根手指来计数。

二进制系统或基数2 (Binary System or Base 2)

Unique Digits = 0, 1

唯一数字 = 0、1

In binary there are only two digits to represent each number so each position is worth two times more than the position to its right.

在二进制中,只有两个数字代表每个数字,因此每个位置的价值是其右边位置的两倍。

Image for post

If we were to count in binary, since we only have two digits to work with, we start with 0, then 1, then 10, 11, 100, 101 and so on. For example, here is binary compared to decimal:

如果要使用二进制,因为我们只有两位数可以使用,所以我们从0开始,然后从1开始,然后是10、11、100、101,依此类推。 例如,这里是二进制而不是十进制:

Image for post

Fun fact: The modern binary number system was studied in Europe in the 16th and 17th centuries however, systems related to binary numbers have appeared earlier in multiple cultures including ancient Egypt, China, and India.

有趣的事实: 现代二进制数系统是在16世纪和17世纪在欧洲研究的,但是,与二进制数有关的系统在包括古埃及,中国和印度在内的多种文化中出现得较早。

八进制或八进制 (Octal System or Base 8)

Unique Digits = 0, 1, 2, 3, 4, 5, 6, 7

唯一数字 = 0、1、2、3、4、5、6、7

We have 8 unique digits to represent values in the octal system. When we get to 7 the next number will be 10, then 11 and so on. Once all of the symbols/digits have been used, we start at 0 again and increase the digit to the left by 1.

我们有8个唯一的数字来代表八进制系统中的值。 当我们达到7时,下一个数字将是10,然后是11,依此类推。 使用完所有符号/数字后,我们再次从0开始,然后将数字向左增加1。

Image for post

Fun fact: The Yuki people, native to California, use the octal system because they count using the spaces between their fingers.

有趣的事实:加利福尼亚州的Yuki人使用八进制制,因为他们使用手指之间的间距进行计数。

十六进制系统或基数16 (Hexadecimal System or base 16)

Unique Digits = 0, 1, 2, 3, 4, 5, 6, 7, 8, 9, A, B, C, D, E, F

唯一数字 = 0、1、2、3、4、5、6、7、8、9,A,B,C,D,E,F

In hexadecimal, we have 16 digits (10 numbers and 6 letters) to represent the values. When we reach 9, next number is represented by the letter A, then B through F. After F comes 10 and so on.

以十六进制形式,我们用16位数字(10个数字和6个字母)表示值。 当我们达到9时,下一个数字由字母A表示,然后由B到F表示。在F到10之后,依此类推。

Image for post

Fun fact: Hexadecimal is often used to represent colors on web pages using the format #RRGGBB (RR = reds, GG = greens, BB = blues). The # (or octothorp) indicates that the number was written in hexadecimal. Each hexadecimal digit is also known as a nibble which represents four binary digits or half a byte.

有趣的事实:十六进制常常用来表示对使用格式#RRGGBB网页中的颜色 (RR =红色,GG =绿色,BB =蓝色)。 #(或octothorp)表示该数字以十六进制表示。 每个十六进制数字也称为半字节,代表四个二进制数字或半个字节。

Now that we have covered a few of the most commonly used numeral systems, let’s get back to parseInt( ). The majority of the time we want to default to base 10, particularly when using the parseInt( ) function so it’s safe to say that we can rely on setting the radix argument to base 10. Keep in mind that parseInt( ) does not default to base 10 so don’t forget to set your radix when using parseInt( ).

现在,我们已经介绍了一些最常用的数字系统,让我们回到parseInt()。 在大多数情况下,我们希望默认设置为以10为底,特别是在使用parseInt()函数时,因此可以肯定地说,我们可以依靠将radix参数设置为10为底。请记住,parseInt()不默认为以10为基数,因此在使用parseInt()时不要忘记设置基数。

parseInt(myNumber, 10)

To get a better feel for the 4 counting systems that we discussed above, I am listing them side-by-side up to 100 in decimal.

为了更好地了解我们上面讨论的4个计数系统,我将它们并排列出(最多十进制)。

Image for post

翻译自: https://medium.com/swlh/numeral-systems-498dd53d7e43

数字系统设计

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值