I need to send some bytes over UDP Protocol the start squence is 0xFF,0xFF,0xFF,0xFF,0xFF,0xFF
When I define like this:
byte [] begin = {0xFF,0xFF,0xFF,0xFF,0xFF,0xFF};
I get an error saying I need to cast those to byte type. Far as I know 0xFF doesn’t exced the byte type so what is the problem ?
If i write this it works :
byte [] begin = {(byte) 0xFF,(byte) 0xFF,(byte) 0xFF,(byte) 0xFF,(byte) 0xFF,(byte) 0xFF};
Actually it does. Bytes are signed in Java, so the range is -0x80 to 0x7f (inclusive).
(The fact that the
bytetype is signed is a pain in the neck, but there we go…)