title: convert 3 bytes to int in java
body: <ol>
  <li><p>I want to convert bytes to int in Java.
  I want to assume bytes to be unsigned bytes.
  Suppose if </p>
  
  <pre><code>byte a = (byte)0xFF;
  
  int r = (some operation on byte a);
  </code></pre>
  
  <p>r should be 255 not -1 in decimal.</p></li>
  <li><p>Then I want to create int value from 3 bytes.
  Suppose if</p>
  
  <pre><code>byte b1 = (byte)0x0F;
  
  byte b2 = (byte)0xFF;
  
  byte b3 = (byte)0xFF;
  
  int r = (some operation in bytes b1, b2 and b3);
  </code></pre>
  
  <p>Then r should be <code>0x000FFFFF</code>. Byte b1 will be placed at higher 3rd position and byte b3 will be placed at lower 1st position in int value. Also my b1 will range from 0x00 to 0x0F and other bytes will be from <code>0x00</code> to <code>0xFF</code>, assuming unsigned nature of bytes. If byte b1 is greater than 0x0F, I will extract only lowermost 4 bits. In short I want to extract int from 3 bytes but using only 20 bits of 3 bytes. (total 16 bits from b2 and b3, and 4 lowermost bits from b1). int r must be positive as we are creating from 3 bytes and assuming unsigned nature of bytes.</p></li>
  </ol>