What does “& 0x7fffffff” mean in “int(time.time()*1000.0) & 0x7FFFFFFF”

It’s a bitmask. In low-level computation, it’s an efficient way to clear out bits of register. In this case, the mask has all bits of a 32 bit integer set, except the signed bit. The signed bit is the bit that determines if the number is positive or negative. ANDing (&) with this mask effectively sets the signed bit to 0, which means the number will always be positive.

a && b is True when both a and b are True.
a & b is 1 when both a and b are 1, for each binary digit in a and b.

Python has support for binary literals, with the 0b prefix. Here are some 3-bit numbers being anded together.

>>> 0b101 & 0b110 == 0b100
>>> 0b011 & 0b111 == 0b011
>>> 0b011 & 0b110 == 0b010

Leave a Comment