Last active
December 30, 2016 01:39
-
-
Save D-Nice/1d9838aeb8fbf1f5e68df5c5c0c17bb4 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
contract stringArrayToBytes { | |
string[] x = ["qs2333332222222222222222222222222233333311", "q2", "q3", "5025", | |
"anotherquery", "oisjgsodjgdsogjsdgsdgsdgsdoigjsdiogjsodigjsdoigjsdog", | |
"777777777", "88888888", "99999", "TEN"]; | |
function convert(string[] x, uint from, uint to) internal returns (bytes) { | |
bytes memory z; | |
uint zlen = 0; | |
for (var i = from; i <= to; i++) { | |
bytes memory y = bytes(x[i]); | |
assembly { | |
let zoffset := 0x20 zlen mul 0x20 add | |
let ylen := y mload | |
let loopctr := 1 | |
ylen z zoffset add mstore | |
zoffset := add(zoffset, 0x20) | |
zlen := add(zlen, 1) | |
loop: | |
y 0x20 loopctr mul add mload | |
z zoffset add mstore | |
zlen := add(zlen, 1) | |
jumpi(loopend, lt(ylen, 0x21)) | |
loopctr := add(loopctr, 1) | |
ylen := sub(ylen, 0x20) | |
zoffset := add(zoffset, 0x20) | |
jump(loop) | |
loopend: | |
} | |
} | |
assembly { | |
mstore(z, mul(0x20, zlen)) | |
} | |
new bytes(z.length); | |
return z; | |
} | |
function pubConv() returns (bytes) { | |
return(convert(x, 0, 9)); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment