Since both types, uint256's and bytes32's space are 2^256. How to map an uint256 type integer into bytes32 type in Solidity ?
Just use bytes32(u)
. It's as easy as that because they are both 2^256 (unlike bytes
).
No need for a separate function, but to clarify:
function convert(uint256 n) returns (bytes32) {
return bytes32(n);
}
bytes32 b
anduint256 u
, then we can dob = bytes32(u)
andu = uint256(b)
. Sorry, can't check now. – Ismael Jun 24 '16 at 18:19