Skip to content

Instantly share code, notes, and snippets.

@raucao
Created July 14, 2017 14:46
Show Gist options
  • Save raucao/818b9c3c9e2658af9f3eaf1dcd4e1044 to your computer and use it in GitHub Desktop.
Save raucao/818b9c3c9e2658af9f3eaf1dcd4e1044 to your computer and use it in GitHub Desktop.
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);
}
}
@bumi
Copy link

bumi commented Jul 14, 2017

@raucao
Copy link
Author

raucao commented Jul 14, 2017

0x7d5a99f603f231d53a4f39d1521f98d2e8bb279cf29bebfd0687dc98458e7f89

@raucao
Copy link
Author

raucao commented Jul 14, 2017

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