忘備録
string to bytes32
bytes32("string");
from std.sol in ether.camp
// contract with util functions
contract util is abstract {
// Converts 'string' to 'bytes32'
function s2b(string s) internal returns (bytes32) {
bytes memory b = bytes(s);
uint r = 0;
for (uint i = 0; i < 32; i++) {
if (i < b.length) {
r = r | uint(b[i]);
}
if (i < 31) r = r * 256;
}
return bytes32(r);
}
}
関連用語
- 型変換
- type casting
- cast