Challenge | Hex decoder |
---|---|
Submitter | ricmoo.firefly.eth |
Submitted at | 2018-14-30 |
Gas used | 1607736 |
contract HexDecoder {
function decode(string input) pure public returns(bytes output) {
output = new bytes(bytes(input).length / 2);
for(uint i = 0; i < output.length; i++) {
uint a = uint(bytes(input)[i * 2]);
uint b = uint(bytes(input)[i * 2 + 1]);
output[i] = byte(
((a + (((a & 0x40) + 1) / 7)) << 4) | ((b & 0x0f) + (((b & 0x40) + 1) / 7))
);
}
}
}