[Ethereum] Operator & not compatible with types bytes32 and int_const

soliditytruffle

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

Best Answer

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);
Related Topic