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位内容
十六进制:0 1 2 3 4 5 6 7 8 9 a b c d e f
*/
bytes1 a1=0x63; //0110 0011
//byte a2=0x632; Type int_const 1586 is not implicitly convertible to expected type bytes1
bytes1 b01 = 0x6c; //0110 1100 10->16 12*16**0 +6*16**1 = 108
bytes1 b11 = 0x69; //0110 1001 10->16 9*16**0 +6*16**1 = 105
//比较操作符 <= , <,>=,>,==,!=
function max() constant returns(bool){
return b01 >= b11; //true
}
//位操作符 &,|,^,~,>>,<<
function test1() constant returns(bytes1){
//return b01 | b11;
/*
0110 1100
0110 1001
0110 1101 ->0x6d
*/
return b01 ^ b11;
/*
0110 1100
0110 1001
0000 0101 -> 0x05
*/
}
//0x03 13 23 33 43 53 63 73 83
// 0 1 2 3 4 5 6 7 8
bytes9 b9 =0x031323334353637383;
function testindex() constant returns(uint){
//return b9[4]; //0x43
return b9.length; //9 .length onlyread
}
//不可变数组 (长度不可变:b.length|内部存储的数据不可变:bytes[0])
/*
function setlen(uint8 a){ //TypeError: Expression has to be an lvalue
b9.length = a;
}
function setvalue(byte a){ //TypeError: Expression has to be an lvalue
b9[0] = a;
}
*/
bytes9 public g = 0x6c697975656368756e; //liyuechun
string public name ='liyuechun';//动态字符串数组
function gByteLength() constant returns(uint){
return g.length;
}
function stingToBytes() constant returns(bytes){
return bytes(name);//还是string类型的动态字节数组
}
function setgByteLength(uint alen){
bytes(name).length = alen;
}
function setgByteValue(bytes1 z){
bytes(name)[0]= z;
}
}
pragma solidity ^0.4.0;
contract byte1{
bytes public b = new bytes(1); //bytes 声明动态大小字节数组
//bytes(1)=0x00 bytes(2)=0x0000 定义变量的初始值,b.push(6c696e) -> b=0x00006c696e
//bytes public b = bytes(1); TypeError: Explicit type conversion not allowed from "int_const 1" to "bytes storage pointer"
function setLeng(uint a) public{ //3 0x000000 |0 0x
b.length = a;
}
function setValus(byte d,uint c ) public{ //0x06,0
b[c] = d;
}
function setclear() public{
delete b;
}
}
ethereum(以太坊)(十一)--字节数组(一)的更多相关文章
- ethereum(以太坊)(十一)--字节数组(二)
pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...
- ethereum(以太坊)(一)
从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛.一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受.有难 ...
- ethereum(以太坊)(四)--值传递与引用传递
contract Person { string public _name; function Person() { _name = "liyuechun"; } function ...
- ethereum(以太坊)(实例)--"安全的远程购买"
pragma solidity ^0.4.10; contract Safebuy{ uint public price; address public seller; address public ...
- ethereum(以太坊)(九)--global(全局函数)
pragma solidity ^0.4.0; contract modifierTest{ bytes32 public blockhash; address public coinbase; ui ...
- ethereum(以太坊)(七)--枚举/映射/构造函数/修改器
pragma solidity ^0.4.10; //枚举类型 contract enumTest{ enum ActionChoices{Left,Right,Straight,Still} // ...
- ethereum(以太坊)(实例)--"简单的公开竞拍"
说真的,刚开始接触这个竞拍案例--“简单的公开竞拍”,我就抱着简单的心态去查看这个实例,但是自我感觉并不简单.应该是我实力不到家的原因吧!!!233333...不过经过大半天的努力,自己理解完之后,觉 ...
- ethereum(以太坊)(十四)--Delete
pragma solidity ^0.4.10; contract Delete{ /* delete可用于任何变量(除mapping),将其设置成默认值 bytes/string:删除所有元素,其长 ...
- ethereum(以太坊)(基础)--容易忽略的坑(三)
pragma solidity ^0.4.10; contract Byte{ bytes [] public T=new bytes[](3); function setLeng(uint len) ...
随机推荐
- SQL——行转列,列转行
行转列,列转行是我们在开发过程中经常碰到的问题.行转列一般通过CASE WHEN 语句来实现,也可以通过 SQL SERVER 2005 新增的运算符PIVOT来实现.用传统的方法,比较好理解.层次清 ...
- Java学习笔记--继承和多态(中)
1.通过继承来开发超类(superclass) 2.使用super 关键词唤起超类的构造方法 3.在超类中覆盖方法 4.区分override和overload 5.在Object类中探索toStrin ...
- javascript 数组方法拼接html标签
var htmls = new Array(); htmls.push("<tr class='otherinfotr'>");htmls.push("< ...
- HihoCoder#1513 : 小Hi的烦恼(五维数点 bitset 分块)
题意 题目链接 Sol 五位数点问题,写个cdq分治套cdq分治套cdq分治套cdq分析就完了 可以用bitset搞 对于每一科开\(n\)个bitset,其中\(b[i]\)表示的排名为\(1 - ...
- display详细说明
display:block,inline,inline-block区别 display:block就是将元素显示为块级元素. block元素的特点是: 总是在新行上开始: 高度,行高以及顶和底边距都可 ...
- base标签
我们扒取到网站源码很多时候发现路径是采用相对路径,这时候我们就需要采用base标签了,用法非常简单, <base href="我们扒取网站的域名"/> 这时相对路径就相 ...
- spring笔记4-事务管理
一.xml配置文件形式 通过转账案例,学习事务管理 1.建立数据库 2.编写entity package huguangqin.com.cnblogs.entity; public class Use ...
- Java Knowledge series 5
Interface from user, not from implementor.(DIP) Interface-Oriented Programming. Interface or Abstrac ...
- Struts2_动态结果集
页面请求: <li><a href="user/user?type=1">返回success</a></li> <li> ...
- webstrom使用
主题 主题下载:http://color-themes.com/?view=index&page=1&order=popular&search=&layout=HTML ...