Casting between uint
s and bytes16
yields different results as that of manipulating the bits directly.
Why? I thought that with casting we were just changing the representation from bits to bytes, and vice versa, but the core numbers stayed the same.
uint b = 54802476401439357 * 1e18;
uint base = 1108895170451311786;
uint b_prime = uint(uint128(bytes16(uint128(base)).ln()));
uint b_prime2 = base.fromUInt().ln().toUInt();
console.log('prime: ', b_prime); //----> 255276110499392941787653382584691046923
console.log('prime2: ', b_prime2);// ---> 42
The fromUInt()
, toUInt()
, and ln()
functions can be found on ABDKMathQuad's library.
Thanks!