For testing purposes, I tried to create an array like this:
byte[] expected = new byte[]{0x2f, 0x0d4, 0xe1, 0xc6, 0x7a, 0x2d, 0x28, 0xfc}
I expected, that java will complain and will ask me to cast every literal here to (byte), but unexpectedly, it asked me only to convert 0x4d, for example, but not 0x2f. The working example:
new byte[]{0x2f, (byte) 0xd4, (byte) 0xe1, (byte) 0xc6, 0x7a, 0x2d, 0x28, (byte) 0xfc}
How does that work?
I suspect it is because the Java byte is signed, thus you have a range between -128 and 127. So all values >127 (0x80) have to be explicitly converted.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With