0

i have the code below:

    uint256 lastBlockNumber = block.number - 1;
    bytes32 hashVal = bytes32(block.blockhash(lastBlockNumber));
    bytes5 _byteData = bytes5((hashVal & 0xffffffff) << 216);

the last line bytes5((hasVal & 0xffffffff) << 216); was working perfectly with solidity 0.4.18 but once i am trying it with 0.5.2 its not working i am getting the error below:

Operator & not compatible with types bytes32 and int_const 4294967295

i am not able to resolve this, any idea on how to resolve it? thank you

  • Have you tried uint256(hashVal) instead? – goodvibration Jun 11 at 7:23
  • @goodvibration i tried it but didnt work – wandos Jun 11 at 8:35
1

i have found the solution below and it worked

    uint256 lastBlockNumber = block.number - 1;
    bytes32 hashVal = bytes32(blockhash(lastBlockNumber));
    bytes5 _byteData = bytes5((hashVal & bytes32(0xffffffff)) << 216);
0

Conversions between bytesX and uintY of different size are now disallowed due to bytesX padding on the right and uintY padding on the left which may cause unexpected conversion results. The size must now be adjusted within the type before the conversion. For example, you can convert a bytes4 (4 bytes) to a uint64 (8 bytes) by first converting the bytes4 variable to bytes8 and then to uint64. You get the opposite padding when converting through uint32.

This is from the docs breaking changes after 0.5.0 pragma version

  • Thank you i have fixed the issue, will post it below – wandos Jun 11 at 8:35

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.