更新一些学习内容

master
土豆兄弟 1 year ago
parent 4dd8b0fefa
commit f55ed8536e

@ -233,11 +233,30 @@ personal.listAccounts
- 位运算符 & | ^ `` - 位运算符 & | ^ ``
- 算术运算 + - * / % ** << >> - 算术运算 + - * / % ** << >>
- 右移 等价于 除法去除以2的几次方 - 右移 等价于 除法去除以2的几次方
- - 常量(literals)
- 字符串常量(String literals) - 有理数和整型常量
- 地址类型(Address) - 有理数的常量计算不会有溢出的
- 字符串常量
- 十六进制常量
- 地址常量
- 地址合法性检查
- 地址类型(Address)
- address: 表示一个账户地址(20个字节)
- 成员: 属性 balance, 函数 transfer()
- 引用类型
- 数据位置(Data location)
- memory, storage
- 数组类型
- 数组(Arrays)
- T[k]: 元素类型为T, 固定长度为k的数组
- T[]: 元素类型为T, 长度动态调整
- bytes string 是一种特殊的数组
- string 可转为 bytes, bytes 类似 byte[]
- 数组类型
- 属性length
- 函数: push()
-

@ -0,0 +1,30 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.8.0;
contract ArrayTest {
// 访 1 => 2
uint [] public u = [1, 2, 3];
string s = "abcdefg";
// => string bytes
function h() public constant returns (uint) {
return bytes(s).length; // 7
}
// 1
function f() public view returns (byte) {
//
g([uint(1), 2, 3]);
return bytes(s)[1]; // b -> asc 0x62
}
//
function g(uint[3] _data) public constant {
}
}

@ -7,9 +7,23 @@ import "solidity_for_import.sol";
contract Test{ contract Test{
// //
uint a; uint a;
int256 b = 20;
int256 c = 30;
bool boola = true; bool boola = true;
bool boolb = false; bool boolb = false;
function testInt() public returns (int) {
if (b > c){
return b + c;
}else if(b == c){
return b * c;
}else {
return b << 2; // b / 2^2
}
-1 >> 2;
}
// //

@ -0,0 +1,19 @@
// SPDX-License-Identifier: UNLICENSED
pragma solidity ^0.4.16;
contract TestAddr {
function deposit() public payable {
}
/* 获取余额 */
function getBalance() public constant returns (uint) {
return this.balance;
}
/* 转移以太 */
function transferEther(address towho) public {
towho.transfer(10); // send
}
}
Loading…
Cancel
Save