title: How to Convert Int to Unsigned Byte and Back
body: <p>I need to convert a number into an unsigned byte. The number is always less than or equal to 255, and so it will fit in one byte.</p>
  
  <p>I also need to convert that byte back into that number. How would I do that in Java? I've tried several ways and none work. Here's what I'm trying to do now:</p>
  
  <pre><code>int size = 5;
  // Convert size int to binary
  String sizeStr = Integer.toString(size);
  byte binaryByte = Byte.valueOf(sizeStr);
  </code></pre>
  
  <p>and now to convert that byte back into the number:</p>
  
  <pre><code>Byte test = new Byte(binaryByte);
  int msgSize = test.intValue();
  </code></pre>
  
  <p>Clearly, this does not work. For some reason, it always converts the number into <code>65</code>. Any suggestions?</p>