Solidity 问题“TypeError:不允许从“uint256”进行显式类型转换”到“地址”
function bytesToAddress(bytes memory b) public view returns (address) {
uint256 result = 0;
for (uint256 i = b.length - 1; i + 1 > 0; i--) {
uint256 c = uint256(uint8(b[i]));
uint256 to_inc = c * (16**((b.length - i - 1) * 2));
result += to_inc;
}
return address(result);
无法弄清楚如何使该功能正常工作。任何帮助表示赞赏
problem is in the last line of code
function bytesToAddress(bytes memory b) public view returns (address) {
uint256 result = 0;
for (uint256 i = b.length - 1; i + 1 > 0; i--) {
uint256 c = uint256(uint8(b[i]));
uint256 to_inc = c * (16**((b.length - i - 1) * 2));
result += to_inc;
}
return address(result);
Can't figure out how to make this function work properly. Any help is appreciated
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
bytes32 值采用十六进制格式。下表显示了 if 语句中的范围是如何计算的
bytes32 values are in hexadecimal format. Here is the table show how ranges in if statement is calculated