zoukankan      html  css  js  c++  java
  • ethereum(以太坊)(六)--整型(int)

    pragma solidity ^0.4.20;
    
    /*
    uint8 uint16 ...uint256
    int8  int16 int24 ..int256
    
    uint => uint256
    int  =>  int256
    
    int8 有符号 +1 ,-3
    uint 无符号 1,2
    
    int8 8(位)
    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 ~ 1111 1111 (0~255)
    */
    
    contract Random{
        
        uint randNonce;
        
        function getRand() public returns(uint){
         // randint:0 - 99 uint id
    = uint(keccak256(abi.encodePacked(randNonce,now,msg.sender))) % 100; randNonce ++; return id; } uint8 a = 3; uint8 b = 7; function yu() view public returns(uint8) { return a & b; // 0000 0011 // 0000 0111 // 0000 0011 = 3 } function huo() view public returns(uint8) { return a | b; // 0000 0111 = 7 } function yihuo() view public returns(uint8) { return a ^ b; // 0000 0100 = 4 } function fei() view public returns(uint8) { return ~b; // 1111 1000 =255-7 = 248 } function add() view public returns(uint) { return a + b ; //10 } function sub() view public returns(uint) { return a - b ; //-4 + 256 = 252 } function mul() view public returns(uint) { return a * b ; // 21 } function div() view public returns(uint) { return b / a ; //2 } function mod() view public returns(uint) { return b % a ; //1 } function mi() view returns(uint){ return b ** a; //343 - 256 = 87 } function leftshit() view returns(uint){ return b << a; // 0000 0111 // 0011 1000 = 56 } function rigthshit() view returns(uint){ return b >> a; // 0000 0111 = 0 } }
  • 相关阅读:
    Git 远程仓库分支管理
    Git 本地仓库管理
    Git 本地仓库管理
    SQLAlchemy_定义(一对一/一对多/多对多)关系
    SQLAlchemy_定义(一对一/一对多/多对多)关系
    自动化生成 Openstack 新项目开发框架
    自动化生成 Openstack 新项目开发框架
    Python 数据结构_队列
    Python 数据结构_队列
    Python 数据结构_堆栈
  • 原文地址:https://www.cnblogs.com/eilinge/p/9957331.html
Copyright © 2011-2022 走看看