如何将 uint256 转换为字节,以及字节转换为 uint256

问题描述 投票:0回答:1

我想发送一系列数字或字母,如“aa5glegd ....”作为 uint256 的 44 字节来调用方法,并在该方法中将其更改为字节,然后将字节转换为 uint256。

ethereum blockchain solidity remix
1个回答
3
投票

使用汇编

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

© www.soinside.com 2019 - 2024. All rights reserved.