zoukankan      html  css  js  c++  java
  • solidity 十六进制字符串转十六进制bytes

    pragma solidity ^0.4.16;
    
    
    contract Metadata {
    
        // 十六进制字符串转换成bytes
        function 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);
        }
    
  • 相关阅读:
    Java--数组转成list,list转数组
    js禁用后退
    正则
    实用符号Alt+小键盘快输
    Minimum Depth of Binary Tree
    Balanced Binary Tree
    Valid Palindrome [leetcode]
    Sum Root to Leaf Numbers
    reorder List
    判断链表 有环
  • 原文地址:https://www.cnblogs.com/bergus/p/solidity-shi-liu-jin-zhi-zi-fu-chuan-zhuan-shi-liu.html
Copyright © 2011-2022 走看看