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(以太坊)(十一)--字节数组(一)的更多相关文章

  1. ethereum(以太坊)(十一)--字节数组(二)

    pragma solidity ^0.4.0; contract test { uint [5] T =[1,2,3,4,5] ;//固定长度的数组:可修改数组内值大小,不支持push,不可更改长度 ...

  2. ethereum(以太坊)(一)

    从这周开始,开始学习以太坊开发--solidity,开始决定往区块链方向发展,毕竟区块链技术应用广泛.一开始接触solidity开发语言不太习惯,毕竟一直在学习python语法,有很多都不能接受.有难 ...

  3. ethereum(以太坊)(四)--值传递与引用传递

    contract Person { string public _name; function Person() { _name = "liyuechun"; } function ...

  4. ethereum(以太坊)(实例)--"安全的远程购买"

    pragma solidity ^0.4.10; contract Safebuy{ uint public price; address public seller; address public ...

  5. ethereum(以太坊)(九)--global(全局函数)

    pragma solidity ^0.4.0; contract modifierTest{ bytes32 public blockhash; address public coinbase; ui ...

  6. ethereum(以太坊)(七)--枚举/映射/构造函数/修改器

    pragma solidity ^0.4.10; //枚举类型 contract enumTest{ enum ActionChoices{Left,Right,Straight,Still} // ...

  7. ethereum(以太坊)(实例)--"简单的公开竞拍"

    说真的,刚开始接触这个竞拍案例--“简单的公开竞拍”,我就抱着简单的心态去查看这个实例,但是自我感觉并不简单.应该是我实力不到家的原因吧!!!233333...不过经过大半天的努力,自己理解完之后,觉 ...

  8. ethereum(以太坊)(十四)--Delete

    pragma solidity ^0.4.10; contract Delete{ /* delete可用于任何变量(除mapping),将其设置成默认值 bytes/string:删除所有元素,其长 ...

  9. ethereum(以太坊)(基础)--容易忽略的坑(三)

    pragma solidity ^0.4.10; contract Byte{ bytes [] public T=new bytes[](3); function setLeng(uint len) ...

随机推荐

  1. SVN仓库连同版本信息迁移新服务器的步骤

    SVN仓库连同版本信息迁移新服务器的步骤 步骤一:导出(1)链接原服务器,找到SVN Server安装路径下的bin文件,并复制文件路径,如 C:\Program File\SVN Server\bi ...

  2. MyBatis01--------概念

    主程序 读取配置 主配置文件 SQL映射文件 1.什么是框架?      ① 框架是一个应用程序的半成品      一个框架程序员可以配置的选择.选项越多,认为这款框架的可扩展性强.       面向 ...

  3. C# 字节数组和十六进制字符串之间转换的另类写法

    今天从http://www.cnblogs.com/NanaLich/archive/2012/05/24/2516860.html看到的,记录下来 主要是XmlSerializationReader ...

  4. mysql-sql命令

    ##本单元目标 一.为什么要学习数据库 二.数据库的相关概念 DBMS.DB.SQL 三.数据库存储数据的特点 四.初始MySQL MySQL产品的介绍 MySQL产品的安装 ★ MySQL服务的启动 ...

  5. spring-boot学习之属性配置

    通过@value注解,将配置文件中的内容引入

  6. Android AS升级3.1 编译报错:The SourceSet 'instrumentTest' is not recognized by the Android Gradle Plugin.

    AndroidStudio升级到3.1后编译报错:The SourceSet ‘instrumentTest’ is not recognized by the Android Gradle Plug ...

  7. 如何使用Nunit进行测试

    如何使用Nunit进行测试(Visual Studio 2017 comminity) 原文:如何使用Nunit进行测试(Visual Studio 2017 comminity) 一.环境 操作系统 ...

  8. 使用uwsgi启动django项目

    在 manage.py 同级目录 创建 uwsgi.ini 文件 ,内容如下: [uwsgi] # 对外提供 http 服务的端口 http = :18123 #the local unix sock ...

  9. Azure 进阶攻略 | 电脑跑分你会,但虚拟机存储性能跑分的正确姿势你造吗?

    想学生时代,小编最爱做的就是研究电脑硬件,然后给自己.朋友和童鞋装机.装好后呢?当然要第一时间跑分了!各种跑分软件运行一遍,不断优化,不断测试.终于得到一个满意成绩,截图分享到网上显摆一下.当年为啥就 ...

  10. 解析Excel文件 Apache POI框架使用

    本文整理了,使用Apache POI 框架解析.读取Excel文件,过程中,程序代码出现的一些问题,并解决 1..xls 和 .xlsx 我们知道Excel文档,在Windows下,分为Excel20 ...