I need to make use of an array of unsigned bytes. I need to send certain characters over the network to a server and some of these characters are greater that 127.
I have a simplified version of the code below to try and understand the concept:
int i= 160;
byte j = (byte) i;
System.out.println((byte)i);
System.out.println(j);
and this gives an output of:
-96
-96
I need to print 160. As the server is expecting a byte of 160 and if it receives -96 it does not accept the value. The reason I used an int is that when I was reading how to get around the problem, I often came across the suggestion to just use an int, but I don't quite understand that, as I need my array to be of type byte.
This is the part of my code where I send the array:
public boolean send(byte[] data) {
try {
out.write(data); // Write the data to the outStream
out.flush();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
return false; // Return false if the TCP Transmit failed
// }
return false;
}
I would really appreciate it if some one could help me.