title: Java and unsigned Bytes
body: <p>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. </p>
  
  <p>I have a simplified version of the code below to try and understand the concept:</p>
  
  <pre><code>int i= 160;
  byte j = (byte) i;
  System.out.println((byte)i);
  System.out.println(j);
  </code></pre>
  
  <p>and this gives an output of:
  <code>-96</code>
  <code>-96</code></p>
  
  <p>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.</p>
  
  <p>This is the part of my code where I send the array:</p>
  
  <pre><code>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;
  }
  </code></pre>
  
  <p>I would really appreciate it if some one could help me.</p>