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;
}
}

最新文章

  1. 【Quartz】将定时任务持久化到数据库
  2. 1Z0-053 争议题目解析701
  3. javascript中this指针
  4. centos文件误删除恢复
  5. java一点小的知识点
  6. c++标准库
  7. 【翻译】CEDCE2010 制作魅力绘制而要知道的光学小知识
  8. 在MVC里面使用Response.Redirect方法后记得返回EmptyResult
  9. Out of Hay
  10. [SAP ABAP开发技术总结]消息处理Messages
  11. Nodepad++ tab改成4个空格
  12. android之手动安装apk到模拟器
  13. 回答了个问题,9x9 乘法表生成器
  14. Island of Survival 概率
  15. Python 2.7 学习笔记 基本知识
  16. jQuery实现的简单分页功能的详细解析
  17. 使用 neon-wallet-db + neon-js + NEO-cli /rpc 搭建轻钱包服务端
  18. Linux内存管理 (1)物理内存初始化
  19. Model First 开发方式
  20. 个股与指数的回归分析(自带python ols 参数解读)

热门文章

  1. HDU 4355——Party All the Time——————【三分求最小和】
  2. netty之==线程模型
  3. AFNetworking 3.0修改指南
  4. 修改默认 JVM 参数 securerandom.source
  5. Java-Excel写与读
  6. 如何解决ArcGIS Runtime SDK for Android中文标注无法显示的问题
  7. mysql-5.7安装配置指导
  8. Java—字符串
  9. Markdown快速上手指南
  10. 04、Spark Standalone集群搭建