Search code examples
cryptographyethereumblockchainsolidityxor

Solidity: What does the caret ^ operator do?


I searched solidity documentation and there's nothing on this:

What does the caret ^ operator do?

What is it doing here?

sha3(sha3(valueA) ^ sha3(valueB))

Solution

  • The keyword I left out is "bitwise" (as Nathan mentioned).

    So, if, for example,               sha3(valueA)=0x44=0b01000100, and
                                       sha3(valueB)=0x34=0b00110100, then:
    (sha3(valueA)=0x44=0b01000100 and sha3(valueB))=0x70=0b01110000
    

    PS fun fact: XOR with all 1s is a "bit flip"