14

Since both types, uint256's and bytes32's space are 2^256. How to map an uint256 type integer into bytes32 type in Solidity ?

Wang
  • 2,416
  • 4
  • 19
  • 28

1 Answers1

18

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);
}
eth
  • 85,679
  • 53
  • 285
  • 406