解决办法
#kotlin
Integer.toHexString(itm.toInt() and(0xff))
#java
Integer.toHexString(itm.toInt() & 0xff)
以下为引用内容,方便查阅
引自https://www.cnblogs.com/cvbaka/archive/2004/01/13/4747337.html
这是因为Integer.toHexString()的接收参数是int,不是byte,于是运算是会先把byte强制转换为int
由于java中强制转换是保持值不变,而在计算机中数都是用补码表示的,java中int是32位4个byte, 正数补码是正数本身,这样不会有问题,强转为32位时前面24位会填充0,
而负数的补码是"将其对应正数二进制表示所有位取反(包括符号位,0变1,1变0)后加1",
于是32位的0x00 00 00 80(0000 ... 0000 1000 0000)补码是0xFF FF FF 80(1111 ... 1111 1000 0000),前面是填充的1
所以Integer.toHexString()后就会变成前面多了一串F
引自https://blog.csdn.net/Jamie_Jiang/article/details/78343549?utm_medium=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param&depth_1-utm_source=distribute.pc_relevant.none-task-blog-BlogCommendFromMachineLearnPai2-1.channel_param
今天学到一句Integer.toHexString(b &