3

Why always when I read some bytes from bytes32 only first read return a value, all following will return zeros? 0x00

bytes32 proof = 0x999e7640514e578f5b9b416469d270d559ad4186ef63da6cd63751373512735e;

bytes1(poof[0]); // some real value, e.g. 0xf2
bytes1(poof[1]); // all following are zeros, e.g. 0x00
bytes1(poof[2]); // all following are zeros, e.g. 0x00

No matter from which index I'm started. Solidity docs says per-byte [] is read only, so what is explanation for such output?

Jesbus
  • 10,478
  • 6
  • 35
  • 62
yanik
  • 473
  • 6
  • 12

1 Answers1

1

Actually, it does work. Apparently, you have a typo there ("proof" and "poof").

Consider this simple contract:

pragma solidity 0.5.4;

contract Test {
    bytes32 public proof = 0x999e7640514e578f5b9b416469d270d559ad4186ef63da6cd63751373512735e;

    function getProofSlice(uint mySlice) public view returns(bytes1) {
        return proof[mySlice];
    }
}

It will compile and it will return the expected values.

Mikhail Vladimirov
  • 7,313
  • 1
  • 23
  • 38
Daniel Portugal
  • 728
  • 4
  • 9