码迷,mamicode.com
首页 > 其他好文 > 详细

ethereum(以太坊)(基础)--容易忽略的坑(二)

时间:2018-12-06 20:16:53      阅读:371      评论:0      收藏:0      [点我收藏+]

标签:ant   depend   rac   --   map   pre   span   value   eth   

pragma solidity ^0.4.0;

contract EMath{
    
    string public _a="lin";
    
    function f() public{
        modify(_a);
    }
    
    //function modify(string storage name) private{
    function modify(string memory name) private{
        //string storage c = name;Type string memory is not implicitly convertible to expected type string storage pointer
        var c = name;
        bytes(c)[0] =‘L‘;
    }
    
    //uint8 ~ uint256
    //0000 0000 ~ 1111 1111
    //0 ~255 
    //int8  ~  int256
    //1111 1111  ~ 0111 1111
    //-127 + 127 +0 =255
    
    uint8 a=3;
    //0000 0011
    uint8 b=6;
    //0000 0110
    function yihuo() view returns(uint){
        return a ^ b;
        /*
            0000 0011
            0000 0110
            0000 0101
        */
    }
    
    function yifeihuo() view public returns(uint16){
        return ~(a ^ (~b));
        /*
            0000 0011
            
            0000 0110
            1111 1001
            
            1111 1010
        */
    }

    function huo() returns(uint){
        return a | b;
        /*
            0000 0011
            0000 0110
            
            0000 0111
        */
    }
    
    function yu() returns(uint){
        return a & b;
        /*
            0000 0011
            0000 0110
            
            0000 0010
        */
    }
    function left() returns(uint8){
        return a<<2;
        /*
            0000 0011
            
            0000 1100                    
        */
    }
    
    enum Cants{left,right,mid}
    
    Cants public def=Cants.left;
    
    function re(Cants c1) returns(bool){
        if (def ==c1){
            return true;
        }
    }
    
    struct fun{
        uint _id;
        string _name;
        uint _sex;
    }
    
    //0x14723a09acff6d2a60dcdf7aa4aff308fddc160c
    //0x4b0897b0513fdc7c541b6d9d7e929c4e5364d2db
    
    
    fun n1=fun(0,‘eilinge‘,1);
    fun n2=fun(1,‘lin‘,0);
    
    fun[] public funs;
    fun[] public funids;
    
    function p1() public{
        funs.push(n1);
        funs.push(n2);
    }
    
    uint funid;
    mapping(address=> fun) addfun;
    
    function p2(address na1) public{
        fun  memory f1 =addfun[na1];
        //f1(2,‘eil‘,0);type is not callable
        f1._id=2;
    }
}

contract Addr{
    address _owner =0xca35b7d915458ef540ade6068dfe2f44e8fa733c;
    uint160 _c = 1154414090619811796818182302139415280051214250812;
    /*
        0x  ca35b7d915458ef540ade6068dfe2f44e8fa733c :.legnth=40
            c       a
        0b  1100  1010                               :.length=40*4=uint160
    */
    function f1() constant returns(uint160){
        return uint160(_owner);
    }
    
    function f2() constant returns(address){
        return address(_c);
    }
    
    function getBalance(address add) payable returns(bool){
        //return add.balance;
        add.transfer(msg.value);//msg.sender => add
    }
    
    bytes1 _a=0xf0;
    //0010 0010; 1*8
    bytes32 public _b=0x231231;
    //32*8
    
    function getLeng() returns(bytes1){
        //return _b.length;
        return _a[0];
    }
    function getLeng1() {
        //_b.length =5;Expression has to be an lvalue
    }
    
    string public _d=‘lilianjie‘;
    //bytes public _f =new bytes;type function (uint256) pure returns (bytes memory) 
                                //is not implicitly convertible to expected type bytes storage ref
    bytes public _f =new bytes(2);
    
    function bytestring() constant returns(bytes){
        return bytes(_d);
    }
    function stringbytes() constant returns(string){
        return string(_f);
    }
    function modifybytes() public{
        //_d.length=5;
        //Member "length" not found or not visible after argument-dependent lookup in string storage ref
        bytes(_d).length=5;
        _f.length=3;
        //_d[0]=‘E‘;Member "length" not found or not visible after argument-dependent lookup in string storage ref

        bytes(_d)[0]="L";
    }
}

 

ethereum(以太坊)(基础)--容易忽略的坑(二)

标签:ant   depend   rac   --   map   pre   span   value   eth   

原文地址:https://www.cnblogs.com/eilinge/p/10078255.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!