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. [转]Java内存溢出详解及解决方案

    原文地址:http://blog.csdn.net/xianmiao2009/article/details/49254391 内存溢出与数据库锁表的问题,可以说是开发人员的噩梦,一般的程序异常,总是 ...

  2. Spring文件下载

    package com.smbea.demo.controller; import java.io.BufferedInputStream; import java.io.BufferedOutput ...

  3. u-boot分析(二)----工作流程分析

    u-boot分析(二) 由于这两天家里有点事,所以耽误了点时间,没有按时更新,今天我首先要跟大家说说我对于u-boot分析的整体的思路,然后呢我以后的博客会按照这个内容更新,希望大家关注. 言归正传, ...

  4. ssh代理登录内网服务器

    服务器 192.168.48.81 # client 192.168.48.82 # bastion 192.168.48.83 # private password方式 192.168.48.81 ...

  5. iBrand 教程:Git 软件安装过程截图

    下载 教程中使用的相关软件下载网盘: https://pan.baidu.com/s/1bqVD5MJ 密码:4lku 安装 请右键 以管理员身份运行 进行软件安装,安装过程如下: 使用 安装完成后, ...

  6. 16 Javascript

    网上找网页模板: 1.HTML模板 2.BootStrap 前面内容总结 HTML 标签:块级,行内 CSS 后台管理布局 position: fixed  ---永远固定在窗口的某个位置 relat ...

  7. nodejs封装的webget webpost方法

    在我之前的项目中,经常用到Nodejs通过post\get方法访问其它网站.webapi.下面是我封装的 Get.Post方法,很适合在一些web字符串收发场景使用(暂不支持文件.二进制流等传输). ...

  8. 323. Number of Connected Components in an Undirected Graph (leetcode)

    Given n nodes labeled from 0 to n - 1 and a list of undirected edges (each edge is a pair of nodes), ...

  9. 【转载】#437 - Access Interface Members through an Interface Variable

    Onece a class implementation a particular interface, you can interact with the members of the interf ...

  10. python里json的排序

    写一下json排序的问题: 将得到的数据转换成json格式传给ajax,会发现前台得到的数据很有可能和我们在后台的内容’不太一样‘,如果不出意外,json进行了自排序处理,至于按什么格式排的我还没研究 ...