Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Java: How to use byte literals greater than 0x7F

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.

like image 599
Zombies Avatar asked Feb 27 '10 03:02

Zombies


1 Answers

Cast them to (byte).

like image 107
PSpeed Avatar answered Sep 23 '22 09:09

PSpeed