1

In solc 0.4.28 I was able to do:

uint foo = 42;
bytes28 bar = bytes28(foo);

but in 0.5.9 I'm getting the error:

TypeError: Explicit type conversion not allowed from "uint256" to "bytes28".
        bytes28 bar = bytes28(foo);
2

I figured it out... You have to cast the uint to the same length so in this case it would be:

bytes28 bar = bytes28(uint224(foo));

If it were bytes16 it would be:

bytes16 bar = bytes28(uint128(foo));

bytes vs bits:
28 / 32 == 224 / 256
16 / 32 == 128 / 256

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.