title: How to clear most significant bit in byte?
body: <p>I want to parse a temperature from bytes.  </p>
  
  <p>The temperature consists of 2 bytes. The most significant bit of the first byte indicates if the temperature is positive or negative. </p>
  
  <p>This is what I have so far:</p>
  
  <pre><code>public double parseTemperatureBytes(byte[] temperatureBytes) {
      // Must be divided by 10 (1 decimal)
      // First bit indicates sign (bit 1 = negative, bit 0 = positive)
      // Range [0x7FFF] : [-3276.7 … +3276.7]
  
      byte firstByte = temperatureBytes[0];
      int positiveOrNegative = ParseUtils.getMostSignificantBit(firstByte);
      boolean isPositive = positiveOrNegative == 0;
  
      String temperatureHex = ParseUtils.bytesToHex(temperatureBytes);
      int temperatureHexToInteger = Integer.parseInt(temperatureHex, 16);
      double temperature = temperatureHexToInteger / (double) 10;
  
      if (!isPositive) {
          temperature = -temperature;
      }
  
      return temperature;
  }
  
  
  // ParseUtils
  
  public static int getMostSignificantBit(byte b) {
      return (b &amp; 0xff) &gt;&gt; 7;
  }
  </code></pre>
  
  <p>This works, but I still have to make sure I ignore the most significant bit of the first byte. It's just a flag and not part of the temperature. </p>
  
  <p>Ex:
  If I pass in 0xFFFF it returns -6553.5 but it should be -3276.7</p>
  
  <p>How can I achieve this? </p>