[Python-Dev] Octal literals

James Y Knight foom at fuhm.net
Thu Feb 2 21:26:24 CET 2006

On Feb 2, 2006, at 7:11 PM, Bengt Richter wrote:
> [1] To reduce all this eye-glazing discussion to a simple example,  
> how do people now
> use hex notation to define an integer bit-mask constant with bits  
> 31 and 2 set?

That's easy:

That was broken in python < 2.4, though, so there you need to do:
MASK = 2**32 - 1
0x80000004 & MASK
> (assume 32-bit int for target platform, counting bit 0 as LSB and  
> bit 31 as sign).

The 31st bit _isn't_ the sign bit in python and the bit-ness of the  
target platform doesn't matter. Python's integers are arbitrarily  
long. I'm not sure why you're trying to pretend as if python was C.


More information about the Python-Dev mailing list