0

I need to send an array of bytes ( few elements have values greater than 0x7F) which I need to send to another device via socket in form of bytes. This I need to do in Java (Android application). As java has only signed byte support hence I store the values in an array of int.

Now to transmit the values over socket to the device so as it could recieve the bytes I am not able to figure out a way.

I can not cast each element in byte and construct byte array as values more than 0x7f will overflow. I can not send values like 0xff in 2 bytes as it will send two bytes with first byte having 0.

Edit:

Suppose I have 2 values 0xff and 0x02 which means 11111111 and 00000010 then how do i store it and then send in java

Edit 2: casting does not result in overflow as byte is 8 bits.

nits.kk
  • 5,204
  • 4
  • 33
  • 55

0 Answers0