【Useful Function】
Mathematical Functions
addmod(uint x, uint y, uint k) returns (uint):以高精度(arbitrary precision)計算 (x + y) % k
mulmod(uint x, uint y, uint k) returns (uint):以高精度(arbitrary precision)計算 (x * y) % k
pragma solidity ^0.8.11;
contract Test {
function callAddMod() public pure returns(uint){
return addmod(4, 5, 3); // 0
}
function callMulMod() public pure returns(uint){
return mulmod(4, 5, 3); // 2
}
}Assert that
k != 0starting from version 0.5.0.
Cryptographic Functions
blockhash(uint blockNumber)returns (bytes32)- 給定一個區塊,返回它的 hash 值, 只有最近工作的256個塊的 hash 值keccak256(bytes memory)returns (bytes32)- 使用 Keccak-256 加密演算法計算之後的結果sha256(bytes memory)returns (bytes32)− 使用 SHA-256 加密演算法計算之後的結果。等同於 Ethereum-SHA3 hash 演算法ripemd160(bytes memory)returns (bytes20)− 使用 RIPEMD-160 加密演算法計算之後的結果
Last updated
Was this helpful?