title: Reading High & Low bits from bytes not working as expected in Java
body: <p>I have a <code>major: 0</code> and <code>minor: 1517</code> version, which is encoded in bytes as follows: [5, -19]</p>
  <p>Where upper 4 bits of first byte represents <code>major</code> version.</p>
  <p>And lower 4 bits of first byte and second byte represents <code>minor</code> version.</p>
  <p>Hex for the same is: <code>05ED</code></p>
  <p><strong>Below is my code that I am using to get the result:</strong></p>
  <pre><code>byte[] data = new byte[] {5, -19};
  int major = data[0] &gt;&gt; 4 &amp; 0x0F;
  int minor = (((data[0] &amp; 0x0F) &lt;&lt; 8) | data[1]) &amp; 0xFFFF_FFFF;
  System.out.println(&quot;Major:&quot; + major + &quot;, Minor:&quot; + minor);
  </code></pre>
  <p><strong>Expected Output</strong>
  <code>Major:0, Minor:1517</code></p>
  <p><strong>Actual Output</strong>
  <code>Major:0, Minor:-19</code></p>
  <p>I am unable to find what I am doing wrong here.</p>
  <p>Can someone help me here?</p>
  <p><strong>Note: Same thing iOS is working fine.</strong></p>
  <p>Thanks in advance</p>