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?

1 Answer 1

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.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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