为什么 JavaScript 输出 16384 而不是 040000? [英] Why does JavaScript output 16384 instead of 040000?
问题描述
我的 JavaScript 程序遇到了一个非常奇怪的问题.我发现 JavaScript 由于某种原因将 040000
更改为 16384
![示例] 有谁知道 JavaScript 为何这样做?
I have encountered a very weird issue with my JavaScript program. I have fount that JavaScript for some reason changes 040000
into 16384
! [Example] Does anyone know why JavaScript is doing this?
推荐答案
因为javascript认为它是OCTAL
格式
Because javascript thinks its in OCTAL
format
说明:-
Javascript
(像大多数编程语言一样)允许我们直接使用 octal
和 hexadecimal
数字,我们需要的是一种方法当我们指定一个数字时,告诉我们正在使用哪个数字基础.为了识别 octal
和 hexadecimal
数字,我们使用这些基数在数字前面添加一些东西,以指示我们使用的基数.数字前面的0
表示后面的数字是八进制的,而0x
前面的表示十六进制的数字.因此,十进制数 18
也可以表示为 022
(在 octal
中)和 0x12
(在 十六进制
).我们不会在十进制数字前面放置特殊符号,因此任何不以 0
或 0x
开头的数字都被假定为十进制.
Javascript
(like most programming languages) allows us to work directly with both octal
and hexadecimal
numbers, all we need is a way to tell which number base we are using when we specify a number. To identify octal
and hexadecimal
numbers we add something to the front of numbers using those bases to indicate which base we are using. A leading 0
on the front of a number indicates that the number following is octal while a leading 0x
indicates a hexadecimal number. The decimal number 18
can therefore also be represented as 022
(in octal
) and 0x12
(in hexadecimal
). We don't put a special symbol on the front of decimal numbers so any number that doesn't start with 0
or 0x
is assumed to be decimal.
所以你的情况是一样的
040000(base8)=16384(base10)
这篇关于为什么 JavaScript 输出 16384 而不是 040000?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!