如何将uint256转换为字节,并将字节转换为uint256

时间:2018-03-12 08:53:54

标签: solidity remix

我想发送一个序列号或字母,如“aa5glegd ....”,44字节作为uint256调用方法,并在该方法中将其更改为字节,然后将字节转换为uint256。但在互联网上有这么多的方法是bytes32

1 个答案:

答案 0 :(得分:0)

使用程序集

function toBytes(uint256 x) returns (bytes b) {
b = new bytes(32);
assembly { mstore(add(b, 32), x) }
}

在此处找到了参考-https://ethereum.stackexchange.com/questions/4170/how-to-convert-a-uint-to-bytes-in-solidity