區塊鏈學堂(20) Int型別

2021-08-14 08:19:07 字數 1284 閱讀 8091

int / uint: signed and unsigned integers of various sizes. keywords uint8 to uint256 in steps of 8 (unsigned of 8 up to 256 bits) and int8 to int256. uint and int are aliases for uint256 and int256, respectively. 引用自here

int代表有符號的整型,也就是可以帶負數

uint代表沒有符號的整型,也就是從0開始的正整數

uint8 代表為2的8次方

uint256 代表為2的256次方

uint 預設為 uint256

int8 代表為-2的7次方到正2的7次方

int256 代表為-2的255次方,到正2的255次方;

int 預設為int256

comparisons: <=, =, >

bit operator: &, |, ^,~

arithmetic operator: +, -, *, /, %, **, <>

最簡單的整型合約,f(n) = 8 * n;
pragma solidity ^0.4.4;

contract demotypes

}

輸入width & height,返回兩者相乘的智慧型合約,加入了if命令
contract demotypes 

}

輸入n,用for迴圈來計算階乘數
contract demotypes 

return result;

}}

輸入n,用for迴圈來計算1+2+3+..+n求和。
contract demotypes 

return result;

}}

所以我們可以在上面的f4()方法的下方,新增一部分測試****如下:

contract demotypes2 

return result;

} function g()

}

增加了乙個可觀察的變數uint public testresult;, 然後在function g()中呼叫f4()方法,這個時候可以通過在browser-solidity中觀察變數testresult即可。

區塊鏈學堂(20) Int型別

int uint signed and unsigned integers of various sizes.keywords uint8 to uint256 in steps of 8 unsigned of 8 up to 256 bits and int8 to int256.uint an...

區塊鏈學堂(24) Struct型別

例如定義乙個struct型別的person struct personpragma solidity 0.4.10 contract demotypes9 person public personlist 最初的合約只定義了struct person型別,以及乙個陣列person personlis...

區塊鏈學堂(15) Mist

建立鏈條的geth命令 geth datadir init genesis.json geth datadir nodiscover console 2 geth.log 在命令列模式下,新建賬號,並且啟動挖礦 personal.newaccount 123 0x48ad44beba68a981e1...