你好,我正在学习 Java 编程,我刚刚在我的书中遇到了一个任务,上面写着转换 int变量转byte变量
byte b;
int i=257;
当我将 int 转换为 b 时
b=(byte) i;
输出是 1 ? 当字节变量的值从 -128 变为 127 时,它如何成为一个 在我的书中,他们说字节变量的有效范围为 256?
最佳答案
257 == 00000000000000000000000100000001 (as integer which holds 32 bits)
1 == 00000001 (byte holds only 8 bits)
关于java - 将整数变量转换为字节变量,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19808612/