Complete the code to pack two uint128 variables into one uint256 variable.
uint256 packed = (uint256(a) << [1]) | uint256(b);We shift a by 128 bits to the left to pack it into the higher half of the 256-bit variable.
Complete the code to unpack the higher 128 bits from a packed uint256 variable.
uint128 a = uint128(packed >> [1]);We shift right by 128 bits to get the higher 128 bits into the lower part, then cast to uint128.
Fix the error in unpacking the lower 128 bits from the packed uint256 variable.
uint128 b = uint128(packed [1] 0xFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFFF);
We use bitwise AND & with a mask to extract the lower 128 bits.
Fill both blanks to pack three uint85 variables into one uint256 variable.
uint256 packed = (uint256(x) << [1]) | (uint256(y) << [2]) | uint256(z);
Shift x by 170 bits (85*2) and y by 85 bits to pack three 85-bit values.
Fill all three blanks to unpack three uint85 variables from a packed uint256 variable.
uint85 x = uint85(packed >> [1]); uint85 y = uint85((packed >> [2]) & [3]);
Shift x by 170 bits, y by 85 bits, and mask with 0x1FFFFFFFFFFFFFFFFFF to extract 85 bits.