title: Putting a short into 2 bytes of string
body: <p>So I'm making my own networking protocol for a online game, to save space each message (sent over TCP) is given a ID which is a short, 2 bytes, all messages sent from the server to the client and vice versa are strings, how can I convert a short to a string in java in just 2 bytes (characters)?</p>
  
  <p><strong>Update:</strong> I'm probably not being clear as to what I want...
  I want to be able to convert a short int into 2 characters, so that I can send the short over the network in a string format in just 2 bytes and decode it back into a short on the other side (in actionscript 3).</p>
  
  <p>A character can hold 256 possible values right? So 256*256=65,536 which is the size of a unsigned short int!</p>
  
  <p>Here's what I've got so far:</p>
  
  <pre><code>public static String toCode(int c){
  
      if(c &lt;= 255 ){
          return Character.toString((char)c);
      }else{
          return null;
      }
  }
  
  public static int fromCode(String c){
      return ((int)c.charAt(0));//Return the character code of the send string, 1 char only
  }
  </code></pre>
  
  <p>This can turn a int into a single character which can be sent over the network, now I just need to have it use 2 characters and it can do up to a short.</p>