Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Insert byte into a byte array

I really can't believe I'm asking this but everything I read is either converting from int to byte to string to byte or something. I am literally trying to insert a byte into a byte array. Or for that matter, initialize a byte array with bytes, not ints.

byte[] header = {0x8b, 0x1f, 0x00, 0x08, 0x00, 0x00, 0x00, 0x00, 0x00, 0x03};

The compiler complains that they are ints. I'm trying to insert bytes.

like image 813
T T Avatar asked Dec 07 '22 11:12

T T


1 Answers

byte is a signed integer in the range [-128,127]. 0x8b is 139d, so you'll need to cast it to a byte (byte)0x8b or use a value in the proper range such as -0x75 (the equivalent of casting 0x8b to byte).

                                                                                        

like image 126
Dave S Avatar answered Dec 09 '22 01:12

Dave S