2012-07-23 17:11:53 +02:00
|
|
|
Bit = {}
|
|
|
|
|
|
|
|
function Bit.bit(p)
|
|
|
|
return 2 ^ p
|
|
|
|
end
|
|
|
|
|
|
|
|
function Bit.hasBit(x, p)
|
2012-07-28 05:54:47 +02:00
|
|
|
return x % (p + p) >= p
|
2012-07-23 17:11:53 +02:00
|
|
|
end
|
|
|
|
|
|
|
|
function Bit.setbit(x, p)
|
|
|
|
return Bit.hasBit(x, p) and x or x + p
|
|
|
|
end
|
|
|
|
|
|
|
|
function Bit.clearbit(x, p)
|
|
|
|
return Bit.hasBit(x, p) and x - p or x
|
|
|
|
end
|