title: Clearing the most significant bit
body: <p>I have a file containing two bytes, in Big Endian order, <code>hexdump</code> gives me:</p>
  
  <p><code>81 50</code></p>
  
  <p>which is <code>1000 0001 0101 0000</code> in binary. However, I want the most significant bit to be a flag, so in golang I have to load the file content, clear the most significant bit, and only then read the value.</p>
  
  <p>So:</p>
  
  <pre><code>valueBuf := make([]byte, 2)
  _, err := f.Read(valueBuf) // now printing valueBuf gives me [129 80] in decimal
  value := int16(binary.BigEndian.Uint16(valueBuf[0:2])) // now value is -32432
  </code></pre>
  
  <p>Ok, I have tried to use something like:</p>
  
  <pre><code>func clearBit(n int16, pos uint) int16 {
      mask := ^(1 &lt;&lt; pos)
      n &amp;= mask
      return n
  }
  </code></pre>
  
  <p>But it apparently doesn't work as expected. The output value should be <code>336</code> in decimal, as normal int, and I cannot get it. How should I do this?</p>