0

I have a simple function printing byte a byte the value of a bytes16 0x20010db8000000000000000000000001 and I get the following result.

['0x20', '0x01', '0x0d', '0xb7', '0xff', '0xff', '0xff', '0x65' ]

[ '0x20', '0x7e', '0x22', '0x36', '0x66', '0xc0', '0x00', '0x00' ]

It should not be??

['0x20', '0x01', '0x0d', '0xb8', '0x00', '0x00', '0x00', '0x00' ]

[ '0x00', '0x00', '0x00', '0x00', '0x00', '0x00', '0x00', '0x01' ]

Why it is not??

Here the code:

function print1(bytes16 a) public 
returns (bytes1,bytes1,bytes1,bytes1,bytes1,bytes1,bytes1,bytes1){
return (a[0],a[1],a[2],a[3],a[4],a[5],a[6],a[7]);}


function print2(bytes16 a) public returns
(bytes1,bytes1,bytes1,bytes1,bytes1,bytes1,bytes1,bytes1){
return (a[8],a[9],a[10],a[11],a[12],a[13],a[14],a[15]);}    

Step to reproduce:

print1(0x20010db8000000000000000000000001);
print2(0x20010db8000000000000000000000001);
1

I tested your code with Remix. But it works fine. If you tested using truffle (javascript test file), then you should use print1("0x20010db8000000000000000000000001"), do not forget "". I got similar issue with byte1 array as here.

enter image description here

And this is truffle result with your code,

enter image description here

plus, both print1 and print2, you better add "pure" to avoid warning, something like..

function print1(bytes16 a) public pure
  • OK that is fine but Why?? – Stefano Angieri Jun 7 '18 at 12:34
  • @StefanoAngieri I am not sure, but it need to explicitly require " " to pass string, bytes, address except number. – Kronos Jun 8 '18 at 12:29

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.