为什么我们需要使用基数?

编程入门 行业动态 更新时间:2024-10-28 20:19:26
本文介绍了为什么我们需要使用基数?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

radix究竟意味着什么?我们为什么需要它?

What does radix actually means? Why do we need it?

parseInt(10, radixValue);

推荐答案

您可能并不总是想要将整数解析为基数为10的数字,因此提供基数允许您指定其他数字系统。

You might not always want to parse the integer into a base 10 number, so supplying the radix allows you to specify other number systems.

基数是单个数字的值的数量。十六进制将是16.八进制将是8,二进制将是2,依此类推...

The radix is the number of values for a single digit. Hexidecimal would be 16. Octal would be 8, Binary would be 2, and so on...

在 parseInt()功能,你可以做几件事来暗示基数而不提供它。如果用户输入的字符串与其中一个规则匹配但不明确表示,则这些也可能对您不利。例如:

In the parseInt() function, there are several things you can do to hint at the radix without supplying it. These can also work against you if the user is entering a string that matches one of the rules but doesn't expressly mean to. For example:

// Numbers with a leading 0 used a radix of 8 (octal) before ECMAScript 5. // These days, browsers will treat '0101' as decimal. var result = parseInt('0101'); // Numbers that start with 0x use a radix of 16 (hexidecimal) var result = parseInt('0x0101'); // Numbers starting with anything else assumes a radix of 10 var result = parseInt('101'); // Or you can specify the radix, in this case 2 (binary) var result = parseInt('0101', 2);

更多推荐

为什么我们需要使用基数?

本文发布于:2023-06-08 02:59:05,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/572843.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:基数

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!