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) ...
随机推荐
- PHP函数的引用传递(地址传递)
PHP中的引用: 在PHP中,变量名和变量内容是不一样的,因此同样的内容可以有不同的名字.在PHP中引用意味着用不同的名字访问同一个变量的内容. 比如:$a = 'hello world'; $b = ...
- SQL语句增删改字段、表、修改默认值
收集转载: 1.修改字段,默认值 .修改字段默认值 alter table 表名 drop constraint 约束名字 ------说明:删除表的字段的原有约束 alter table 表名 ad ...
- Spring自定义注解配置切面实现日志记录
一: spring-mvc.xml: <!--配置日志切面 start,必须与mvc配置在同一个配置文件,否则无法切入Controller层--><!-- 声明自动为spring容器 ...
- HTML的行内元素与块级元素的区别?
块级元素:独占一行,其宽度自动填满父元素的宽度,可以容纳行内元素和其他块级元素,可以设置margin和padding值. 行内元素:不会独占一行,与其他行内元素排成一行,直到其父元素拍不下,才会从新一 ...
- The fifth day
All men cannot be first . 今日单词: first(形容词):第一的:基本的:最早的:(副词):第一:首先 翻译:不可能人人都是第一名. <Only Love>-- ...
- Hive建模
Hive建模 1.介绍 Hive作为数据仓库,同关系型数据库开发过程类似,都需要先进行建模,所谓建模,就是对表之间指定关系方式.建模在hive中大致分为星型.雪花型和星座型.要对建模深入理解,首先需要 ...
- Android(java)学习笔记68:使用proguard混淆android代码
1. 当前是有些工具比如apktool,dextojar等是可以对我们android安装包进行反编译,获得源码的.为了减少被别人破解,导致源码泄露,程序被别人盗取代码,等等.我们需要对代码进行混淆,a ...
- Eclipse快捷键功能
转载一篇另人写的:https://blog.csdn.net/qq_30617755/article/details/50781003 Eclipse的编辑功能非常强大,掌握了Eclipse快捷键功能 ...
- JS中如何得到触发事件的属性?
<html xmlns="http://www.w3.org/1999/xhtml"><head runat="server"> ...
- Deep Learning Libraries by Language
Deep Learning Libraries by Language Tweet Python Theano is a python library for defining and ...