title: Converting from byte array to short producing wrong negative value
body: <p>It's been a while since I've done operations at the bit/byte level so please forgive me if this is simple.</p>
  
  <p>I'm receiving data over a TCP socket in a Java application from an embedded device.  The data is little endian (least significant byte first) and I'm currently trying to grab <code>short</code> values out of an array of data.  To do this, I'm using the following code:</p>
  
  <pre><code>byte[] valBytes = {data[0], data[1]};
  short val = EndianArrayUtils.getShortFromLittleEndianRange(valBytes);
  </code></pre>
  
  <p>This works fine for positive numbers, but when the <code>short</code> should be -1, I'm getting -2 instead.  The data that produces -2 is:</p>
  
  <pre><code>byte[] valBytes = {(byte)0xff, (byte)0xff};
  short val = EndianArrayUtils.getShortFromLittleEndianRange(valBytes);
  </code></pre>
  
  <p>Am I missing something?  -1 in two's complement should be <code>11111111 11111111</code> correct?</p>
  
  <p><strong>Edit</strong></p>
  
  <p>I completely forgot that I was the one that actually wrote <code>EndianArrayUtils</code>. The code for the <code>getShortFromLittleEndianRange</code> method is</p>
  
  <pre><code>public static short getShortFromLittleEndianRange(byte[] range){
          return (short)((short)(range[1] &gt;&gt; 8) + (short)(range[0]));
      }
  </code></pre>
  
  <p>Obviously there's something wrong with how that's operating on negative numbers.</p>