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

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";
    }
}

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

时间: 2024-07-31 03:34:17

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

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

pragma solidity ^0.4.0; contract base{ address public _owner=msg.sender; uint _a; string internal _b ; uint private _c; //uint external _d;ParserError: Expected identifier but got 'external' function base() { _a =10; //uint _d public;Expected ';' but

以太坊基础福运来平台制作

控制和责任像以太坊福运来平台制作请添加链接描述Q_1151880099这样的开放区块链是安全的,因为它们是去中心化的.这意味着以太坊的每个用户都应该控制自己的密钥,这些密钥可以控制对资金和合约的访问.一些用户选择通过使用第三方保管人(比如交易所钱包)放弃对密钥的控制权.在本书中,我们将教你如何控制和管理你自己的密钥. 这种控制带来了很大的责任.如果你丢失了你的钥匙,你将无法获得资金和合约.没有人可以帮助你重新获得访问权 - 你的资金将永远锁定.以下是一些帮助你管理这一责任的提示: 提示你选择密码

区块链:以太坊基础之安装Geth

1.安装cmake 智能合约需要cmake3.x版本才可以编译 # 下载包 wget https://cmake.org/files/v3.3/cmake-3.3.2.tar.gz # 解压 tar zxvf cmake-3.3.2.tar.gz cd cmake-3.3.2 # 安装 ./configure make make install # 编辑环境变量配置文件 vim /etc/profile # 在末尾加上 export PATH=/usr/cmake/cmake-3.3.2/bin

ethereum(以太坊)(五)--Bool

pragma solidity ^0.4.0; contract Bool{ uint num1 = 100; uint num2 = 200; bool _c = true; // && == function yuf() constant returns(bool){ return num1 == num2 && _c; //false } // || != function huof() constant returns(bool){ return num1 != n

ethereum(以太坊)(六)--整型(int)

/* uint8 uint16 ...uint256 int8 int16 int24 ..int256 uint => uint256 int => int256 int8 有符号 +1 ,-3 uint 无符号 1,2 int8 8(位) 1 111 1111 ~ 0 111 1111 - (1+2+4+8+16+32+64) ~ + (1+2+4+8+16+32+64) -127 ~ 127 255(127*2+0) uint8 0000 0000 ~ 1111 1111 (0~255)

ethereum(以太坊)(九)--global(全局函数)

pragma solidity ^0.4.0; contract modifierTest{ bytes32 public blockhash; address public coinbase; uint public difficulty; uint public gaslimit; uint public blockNum; uint public timestamp; bytes public calldata1; uint public gas; address public sende

ethereum(以太坊)(十)--字节数组

pragma solidity ^0.4.0; contract byte1{ /* 固定大小字节数组(Fixed-size byte arrays) 固定大小字节数组可以通过bytes1,bytes2...bytes32声明,byte=byte1 bytes1 只能存储1个字节,也就是二进制的8位内容 //一个字节=8位2进制/一个字母/符号/(1/3汉字) bytes2 只能存储2个字节,也就是二进制的8*2位内容 bytes32 只能存储32个字节,也就是二进制的8*32=256位内容 十

ethereum(以太坊)(十四)--Delete

pragma solidity ^0.4.10; contract Delete{ /* delete可用于任何变量(除mapping),将其设置成默认值 bytes/string:删除所有元素,其长度变为0 bytes32:重置所有索引的值 mapping:什么都不会发生 mapping(key=>value)中的key:删除与该键相关的值 */ string public str1 ='nihao'; function deletstr() public{ delete str1; } fu

区块链:以太坊基础之搭建私链

1.新建genesis.json {  "config": {    "chainId": 666,    "homesteadBlock": 0,    "eip150Block": 0,    "eip150Hash": "0x0000000000000000000000000000000000000000000000000000000000000000",    "eip