title: Python Integer Bit masking while keeping sign
body: <p>I am trying to replicate/validate bitwise arithmetic logic in Python.
  I have cases where bits from the absolute value are truncated (no matter if they are 0 or 1) while the sign is preserved. This happens in various bit length representations.
  <strong>How to implement truncating bits from the absolute value also for negative integers elegantly in Python ?</strong></p>
  
  <p>For positive integers I can easily apply a bit mask:</p>
  
  <pre><code>n=7; nMod=n &amp; 0b11; print(nMod) #truncate MSB
  #expected and actual: 3
  </code></pre>
  
  <p>For negative integers it does not work, probably due to the internal 2's complement and variable number of bits representation:</p>
  
  <pre><code>n=-7; nMod=n &amp; 0b11; print(nMod)
  #expected:-3; actual: 1
  </code></pre>
  
  <p>One could certainly analyze the absolute value, determine which bits are actually Ones and remove them by shifting left and right but my wish would be a simple one-liner like for the positive numbers.</p>