Solidity:插入符号 ^ 运算符的作用是什么?
Solidity: What does the caret ^ operator do?
我搜索了 solidity 文档,没有关于此的内容:
插入符号 ^ 运算符的作用是什么?
它在这里做什么?
sha3(sha3(valueA) ^ sha3(valueB))
Per https://www.tutorialspoint.com/solidity/solidity_operators.htm(通过Google,顺便说一句),在许多语言中,它表示异或(异或):
x y x^y
0 0 0
0 1 1
1 0 1
1 1 0
(1=True; 0=False)
是位运算,异或(异或):https://docs.soliditylang.org/en/v0.8.6/types.html
"按位异或是一种二进制运算,取两个等长的位模式,对每一对对应的位进行逻辑异或运算。如果只有一个位为1,则每个位置的结果为1 ,但如果两者均为 0 或均为 1,则为 0。” https://en.wikipedia.org/wiki/Bitwise_operation#:~:text=A%20bitwise%20XOR%20is%20a,0%20or%20both%20are%201.
我遗漏的关键字是“按位”(正如 Nathan 提到的)。
So, if, for example, sha3(valueA)=0x44=0b01000100, and
sha3(valueB)=0x34=0b00110100, then:
(sha3(valueA)=0x44=0b01000100 and sha3(valueB))=0x70=0b01110000
PS
有趣的事实:全 1 的 XOR 是“位翻转”
我搜索了 solidity 文档,没有关于此的内容:
插入符号 ^ 运算符的作用是什么?
它在这里做什么?
sha3(sha3(valueA) ^ sha3(valueB))
Per https://www.tutorialspoint.com/solidity/solidity_operators.htm(通过Google,顺便说一句),在许多语言中,它表示异或(异或):
x y x^y
0 0 0
0 1 1
1 0 1
1 1 0
(1=True; 0=False)
是位运算,异或(异或):https://docs.soliditylang.org/en/v0.8.6/types.html
"按位异或是一种二进制运算,取两个等长的位模式,对每一对对应的位进行逻辑异或运算。如果只有一个位为1,则每个位置的结果为1 ,但如果两者均为 0 或均为 1,则为 0。” https://en.wikipedia.org/wiki/Bitwise_operation#:~:text=A%20bitwise%20XOR%20is%20a,0%20or%20both%20are%201.
我遗漏的关键字是“按位”(正如 Nathan 提到的)。
So, if, for example, sha3(valueA)=0x44=0b01000100, and
sha3(valueB)=0x34=0b00110100, then:
(sha3(valueA)=0x44=0b01000100 and sha3(valueB))=0x70=0b01110000
PS 有趣的事实:全 1 的 XOR 是“位翻转”