//Write your own contracts here. Currently compiles using solc v0.4.15+commit.bbb8e64f. pragma solidity ^0.4.17; contract TestBits { // Let's test uint256 value 26322820181848127205119429488744061657188852288741917040354512141634951523633: // which in hex format is: // 0x3a32303138313133303030303030302b30383030000100005649500000412d31 function test1() public pure returns(bytes){ uint256[] memory tickets = new uint256[](1); tickets[0] = 26322820181848127205119429488744061657188852288741917040354512141634951523633; bytes memory message = new bytes(tickets.length * 32); for (uint i = 0; i < tickets.length; i++){ for (uint j = 0; j < 32; j++) { message[i * 32 + j] = byte(bytes32(tickets[i] << (8*j))); } } //expected //0x3a32303138313133303030303030302b30383030000100005649500000412d31 return message; } function test2() public pure returns(bytes){ uint256[] memory tickets = new uint256[](1); tickets[0] = 26322820181848127205119429488744061657188852288741917040354512141634951523633; bytes memory message = new bytes(tickets.length * 32); for (uint i = 0; i < tickets.length; i++){ for (uint j = 0; j < 32; j++) { message[i * 32 + j] = byte(tickets[i] << (8*j)); } } // 0x3100000000000000000000000000000000000000000000000000000000000000 // only contains the last byte return message; } }
0.4.18