title: How to perform unsigned to signed conversion in Java?
body: <p>Say I read these bytes: "6F D4 06 40" from an input device. The number is a longitude reading in MilliArcSeconds format. The top bit (0x80000000) is basically always zero and is ignored for this question. </p>
  
  <p>I can easily convert the bytes to an <em>unsigned</em> integer: 1876166208</p>
  
  <p>But how do I convert that unsigned value into its final form of 31-bit signed-integer? </p>
  
  <p>So far all I've come up with is: </p>
  
  <ol>
  <li>if value &amp; 0x40000000 then it's actually negative, need to convert it</li>
  <li>If it's negative, strip the top bit and do something with the remaining bits...</li>
  </ol>
  
  <p>So I can tell if it's a negative number, but in order to know what value the negative number is, I have to do something with the remaining bits - a one's compliment? How do I do that in Java?</p>
  
  <p>Another way to put the question is, how do I convert an unsigned integer into a 31-bit signed integer in Java?</p>
  
  <p>Thank you!</p>