Solidity – How to Convert a uint to Bytes

bytescontract-developmentsolidity

Is there an easy way to convert a uint to bytes in Solidity?

Best Answer

It seems there now is, since solidity version 0.4.24 you can use abi.encodePacked

E.G:

uint i = 0;
i_bytes = abi.encodePacked(i);