title: Reading least significant bits in Python
body: <p>I am having to parse the Facility and Severity of syslog messages in Python.  These values come with each message as a single integer.  The severity of the event is 0-7, specified in the 3 least significant bits in the integer.  What is the easiest/fastest way to evaluate these 3 bits from the number?</p>
  
  <p>The code I have right now just does a 3 bit right shift, than multiplies that number times 8, and subtracts the result from the original.</p>
  
  <pre><code>FAC = (int(PRI) &gt;&gt; 3)
  SEV = PRI - (FAC * 8)
  </code></pre>
  
  <p>There must be a less convoluted way to do this- rather than wiping out the bits, and subtracting.</p>