Skip to content

Instantly share code, notes, and snippets.

@Arachnid
Created April 7, 2016 21:14
Show Gist options
  • Save Arachnid/db6dae7ad3be00e090d60597e221740f to your computer and use it in GitHub Desktop.
Save Arachnid/db6dae7ad3be00e090d60597e221740f to your computer and use it in GitHub Desktop.
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