本文介绍了长值,左边为0的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么会出现这种情况?
Why this behavior happens?
long value = 123450;
System.out.println("value: " + value);
价值:123450
long value = 0123450;
// ^
System.out.println("value: " + value);
价值:42792
这是什么42792?
What is this 42792?
推荐答案
正如以 0x
开头的文字被视为十六进制数字(基数为16),文字以a开头 0
被视为,即基数为8的数字。
Just as literals starting with 0x
are treated as hexadecimal numbers (base 16), literals starting with a 0
are treated as octal numbers, i.e., numbers in base 8.
(尝试编写0789,你会看到编译器会抱怨。)
(Try writing 0789, and you'll see that the compiler will complain.)
基数8中的数字123450代表数字
The number 123450 in base 8 represents the number
1 &次; 8 + 2 × 8 + 3 × 8 + 4 × 8 + 5 × 8 + 0 × 8 = 42792
1×8 + 2×8 + 3×8 + 4×8 + 5×8 + 0×8 = 42792
这篇关于长值,左边为0的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!