function guessNumber(uint256 _num) public { uint256 num = _num;
assembly { let m := mload(0x40) let a := and(sload(secretNumber_slot), 1) let b := and(num, 1) let result := eq(a, b) mstore(m, result) sstore(solved_slot, result) } }
function isSolved() public view returns (bool) { return solved; } }
function guessNumber(uint256 _num) public { uint256 num = _num;
assembly { let m := mload(0x40) let a := and(sload(secretNumber_slot), 1) let b := and(num, 1) let result := eq(a, b) mstore(m, result) sstore(solved_slot, result) } }
接受一个_num参数使用汇编来比较secretNumber 的最低位和 _num 的最低位是否相等。 如果相等,将 result 设置为 true,否则为 false。最后,将 result 存储在 solved 变量中。