Created
July 14, 2017 14:46
-
-
Save raucao/818b9c3c9e2658af9f3eaf1dcd4e1044 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
pragma solidity ^0.4.0; | |
library ipfsUtils { | |
function splitHash(bytes source) returns(bytes1, bytes1) { | |
bytes1[2] memory hash = [bytes1(0), bytes1(0)]; | |
assembly { | |
mstore(hash, source) | |
mstore(add(hash, 1), source) | |
} | |
return (hash[0], hash[1]); | |
} | |
} | |
contract Foo { | |
function bar(bytes source) returns(bytes1, bytes1) { | |
return ipfsUtils.splitHash(source); | |
} | |
} |
0x7d5a99f603f231d53a4f39d1521f98d2e8bb279cf29bebfd0687dc98458e7f89
contract cutByte32 {
//"0xa9c40ddcb43ebbc83add97b8f9f361f12b19bceff2f76b68f66b5bb1812365a9"
//use this as remix command
function cut(bytes32 sha) constant returns (uint8 tag, uint8 len, bytes32 hash) {
assembly {
let freemem_pointer := mload(0x40)
mstore(add(freemem_pointer,0x00), sha)
hash := mload(add(freemem_pointer,0x00))
}
}
}
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
https://solidity.readthedocs.io/en/develop/assembly.html