solidity智能合约[12]-固定字节数组相互转换

固定字节数组相互转换

固定长度字节数组之间能够进行相互转换

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
pragma solidity ^0.4.23;

contract fixTofix{

bytes6 name = 0x6a6f6e736f6e;

//bytes1: 0x6a
function Tobytes1() view public returns(bytes1){
return bytes1(name);
}
//bytes2: 0x6a6f
function Tobytes2() view public returns(bytes2){
return bytes2(name);
}
// bytes8: 0x6a6f6e736f6e0000
function Tobytes3() view public returns(bytes8){
return bytes8(name);
}

}