什么是XOR的逆函数?


91

Java中有XOR函数- a^b

举个例子: 5^3 = 6

你能告诉我反函数吗?如果有6,我3能否获得包括数字在内的数字范围5

Answers:


194

反之为XOR!

如果你有:

c = a^b;

如果您有其他可用值,则可以获取ab返回:

a = c^b; // or b^c (order is not important)
b = c^a; // or a^c

例如,如果a = 5b = 3c = 6如您所说),您将获得:

b=0011 (3)            a=0101 (5)
c=0110 (6) XOR   or   c=0110 (6) XOR
----------            ----------
a=0101 (5)            b=0011 (3)

By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.