Created
April 7, 2016 21:14
-
-
Save Arachnid/db6dae7ad3be00e090d60597e221740f 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 CopyTest { | |
function bytesToBytes32(bytes data) returns (bytes32 out) { | |
assembly { | |
out := mload(add(data, 32)) | |
} | |
} | |
function bytes32ToBytes(bytes32 data, uint8 length) returns (bytes out) { | |
out = new bytes(length); | |
assembly { | |
mstore(add(out, 32), data) | |
} | |
} | |
function testBytesToBytes32() returns(bytes32) { | |
return bytesToBytes32("foobarbaz"); | |
} | |
function testBytes32ToBytes() returns (bytes) { | |
return bytes32ToBytes("foobarbaz", 9); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment