问题
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