2014-05-12 22:27:29 +00:00
|
|
|
print(0 & (1 << 80))
|
|
|
|
print(0 & (1 << 80) == 0)
|
|
|
|
print(bool(0 & (1 << 80)))
|
|
|
|
|
2014-05-29 14:01:49 +00:00
|
|
|
a = 0xfffffffffffffffffffffffffffff
|
|
|
|
print(a & (1 << 80))
|
|
|
|
print((a & (1 << 80)) >> 80)
|
|
|
|
print((a & (1 << 80)) >> 80 == 1)
|
|
|
|
|
|
|
|
# test negative on rhs
|
|
|
|
a = 123456789012345678901234567890
|
|
|
|
print(a & -1)
|
|
|
|
print(a & -2)
|
|
|
|
print(a & -2345678901234567890123456789)
|
|
|
|
print(a & (-a))
|
2015-03-14 21:20:58 +00:00
|
|
|
print(a & (-a - 1))
|
|
|
|
print(a & (-a + 1))
|
2014-05-29 14:01:49 +00:00
|
|
|
|
|
|
|
# test negative on lhs
|
|
|
|
a = 123456789012345678901234567890
|
|
|
|
print(-1 & a)
|
|
|
|
print(-2 & a)
|
|
|
|
print(-2345678901234567890123456789 & a)
|
|
|
|
print((-a) & a)
|
|
|
|
print((-a) & 0xffffffff)
|
|
|
|
print((-a) & 0xffffffffffffffffffffffffffffffff)
|
2015-10-01 21:35:06 +00:00
|
|
|
print((-a) & 2)
|
|
|
|
print((-(1 << 70)) & 2)
|
2016-01-31 03:35:58 +00:00
|
|
|
|
|
|
|
# test negative on lhs and rhs
|
|
|
|
mpz = 1 << 70
|
|
|
|
a = 123456789012345678901234567890
|
|
|
|
print(-1 & (-a))
|
|
|
|
print(-2 & (-a))
|
|
|
|
print(-2345678901234567890123456789 & (-a))
|
|
|
|
print((-a) & (-a))
|
|
|
|
print((-a) & (-0xffffffff))
|
|
|
|
print((-a) & (-0xffffffffffffffffffffffffffffffff))
|
|
|
|
print((-1) & (-0xffffffffffffffffffffffffffffffff))
|
|
|
|
print((-a) & (-2))
|
|
|
|
print((-mpz) & (-2))
|