这样的数字在Java中是什么意思:0b1000_1100_1010? (数字之间的“ b”)

问题描述 投票:0回答:1

我正在练习Java课程的某些任务,但是遇到了这个变量

int x = 0b1000_1100_1010;

我知道数字旁边的“ f”和“ d”分别表示该数字是floatdouble。但是这个“ b” between数字呢?

我看到here这与bytes有关,但我不太了解它是如何工作的。

我的问题也适用于我刚刚在该链接上看到的数字之间的“ x”。

谢谢!

java primitive-types
1个回答
3
投票

这是表示数字以二进制表示的符号。

就像使用十六进制表示法:0xF9。在Java中,您可以使用`0b1111_1001代表相同的数字,即249。


0
投票
The byte data type is an 8-bit signed two's complement integer. It has a minimum value of -128 and a maximum value of 127 (inclusive). The byte data type can be useful for saving memory in large arrays, where the memory savings actually matters. They can also be used in place of int where their limits help to clarify your code; the fact that a variable's range is limited can serve as a form of documentation.

https://docs.oracle.com/javase/tutorial/java/nutsandbolts/datatypes.html

© www.soinside.com 2019 - 2024. All rights reserved.