11

Just tried to convert byte to uint using Solidity 0.5.x:

uint length = uint(arr[i]);

and got:

MyCode.sol:88:29: TypeError: Explicit type conversion not allowed from "bytes1" to "uint256".
       uint length = uint(arr[i]);
                          ^----^

1 Answer 1

17

The shortest solution I discovered after several tries:

uint256 length = uint256(uint8(arr[i]));

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.