Java: How to use byte literals greater than 0x7F

不问归期 提交于 2020-01-24 04:07:45

问题


In Java, I can't take a byte array of unsigned bytes (from something such as Wire Shark) and put this into java.... Because I will get compile errors since anything greater than 127 decimal/0x07F is treated not as a byte, but as an int.... IE:

        byte[] protocol = { 0x04, 0x01, 0x00, 0x50, /*error*/0xc1, /*error*/0xdb, 0x1c, /*error*/0x8c, 
                0x4d, 0x4f, 0x5a, 0x00 };

Need a good way to handle taking unsigned char arrays and putting them into Java as literals.


回答1:


Cast them to (byte).



来源:https://stackoverflow.com/questions/2346101/java-how-to-use-byte-literals-greater-than-0x7f

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!