Code in UniswapV3 Solidity contract TickBitmap
uint256 mask = ~((1 << bitPos) - 1);
I had founded some example code in Golang:
a := new(big.Int).Exp(big.NewInt(2), big.NewInt(66), nil)
a.Sub(a, big.NewInt(1))
b := bitwiseNot(a)
func bitwiseNot(x *big.Int) *big.Int {
mask := new(big.Int).SetBit(new(big.Int), 256, 1)
result := new(big.Int).Xor(x, mask)
return result
}
When I Test code on Remix, try bitpos=66
,
Remix Output:
uint256: mask 115792089237316195423570985008687907853269984665640564039383797031618291433472
Golang Output:
115792089237316195423570985008687907853269984665640564039531370984207967846399
How to implement this solidity caculation in golang?