solidity 十六进制字符串转十六进制bytes
生活随笔
收集整理的這篇文章主要介紹了
solidity 十六进制字符串转十六进制bytes
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
pragma solidity ^0.4.16;contract Metadata {// 十六進制字符串轉換成bytesfunction hexStr2bytes(string data)returns (bytes){uint _ascii_0 = 48;uint _ascii_A = 65;uint _ascii_a = 97;bytes memory a = bytes(data);uint[] memory b = new uint[](a.length);for (uint i = 0; i < a.length; i++) {uint _a = uint(a[i]);if (_a > 96) {b[i] = _a - 97 + 10;}else if (_a > 66) {b[i] = _a - 65 + 10;}else {b[i] = _a - 48;}}bytes memory c = new bytes(b.length / 2);for (uint _i = 0; _i < b.length; _i += 2) {c[_i / 2] = byte(b[_i] * 16 + b[_i + 1]);}return c;}
}
solidity 智能合約 從公鑰得到賬戶地址
function pk2account(address _address) public returns (address) {uint160 m = 0;uint160 tmp = 0;m = uint160(_address);tmp >>= 80;tmp <<= 80;m-=tmp;return address(m);}轉載于:https://www.cnblogs.com/bergus/p/solidity-shi-liu-jin-zhi-zi-fu-chuan-zhuan-shi-liu.html
總結
以上是生活随笔為你收集整理的solidity 十六进制字符串转十六进制bytes的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: 【网络流24题】【LOJ6224】深海机
- 下一篇: SpringMVC(2)—SpringM