title: How to select some bits from byte?
body: <p>I want to get some bits from a byte, like this:</p>
  
  <p>251 dec = 11111011 bin</p>
  
  <p>I want to get bit 3 until bit 6.</p>
  
  <p>I created a function:</p>
  
  <pre><code>function ExtractBitsRL (value, bits_start, bits_len: Integer) : Integer;
  begin
    Result := ((value shr (bits_start - 1)) and ((1 shl bits_len) - 1));
  end;
  </code></pre>
  
  <p>Usage:</p>
  
  <pre><code>b := ExtractBitsRL (251,3,3);
  </code></pre>
  
  <p>And the result is: 110  is OK.</p>
  
  <p>But</p>
  
  <pre><code>b := ExtractBitsRL (176,1,4);
  </code></pre>
  
  <p>176 dec = 10110000 bin</p>
  
  <p>the result is: 0000 not 1011</p>
  
  <p>I cannot find my mistake. (I'm using Delphi 7)</p>