I understand what add() does. It used used in the assembly to perform additions. My question is why are we adding 32 here? What is the purpose of doing so?

The full code is here

1 Answer 1


To better understand it is better to include part of the function

function stringToBytes32(string memory source) public pure returns (bytes32 result) {
    // ..

    assembly {
        result := mload(add(source, 32))

source is a memory string so the first 32 bytes contains the length and data follows. Then add(source, 32) skips the size portion of the string, and points to the data.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.