title: Bitwise operations in Python
body: <p>I'm looking for recommendations on how to do bitwise math in python. </p>
  
  <p>The main problem I have is that python's bitwise operators have infinite precision, which means that -1 is really "111.......111". That's not what I want. I want to emulate real hardware which will have some fixed precision, say 32 bits.</p>
  
  <p>Here are some gotchas: </p>
  
  <p>1) -n should return a 32 bit 2's complement number ( this is easily achieved by taking the lower 32 bits of the infinite precision -n )</p>
  
  <p>2) n >> 3, should be an arithmetic shift of a 32 bit number, which means if bit 31 is '1', then bits 31:28 should be '1' after the shift by 3.</p>