我在下面的代码中使用以下枚举类型:
public static enum PanelType
{
PAS8((byte)0xA6), PAS83((byte)0xA7);
private byte code;
private PanelType(byte code)
{
this.code=code;
}
public byte getCode(){
return code;
}
}
Run Code Online (Sandbox Code Playgroud)
但是,当我在我的方法中尝试使用它时:
for (PanelType type:PanelType.values())
{
if (decoded[3]==type.getCode())
return type;
}
Run Code Online (Sandbox Code Playgroud)
我正在为:type.getCode()method 返回不正确的值.它返回-90而不是166,这正是我所期待的.
我知道FFFF FFFF FFFF FFA6 = -90,但为什么0xA6作为负数返回?
bytes的最大值为127,最小值为-128.0xA6十进制是166,所以有一个溢出:
-128 + (166 - 127 - 1) == -90
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2022 次 |
| 最近记录: |