Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

There is XOR function in Java - a^b

For exemple: 5^3 = 6

Can you tell me inverse function? If I have 6 and 3 can i get range of numbers which include number 5?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
125 views
Welcome To Ask or Share your Answers For Others

1 Answer

The inverse is XOR!

If you have:

c = a^b;

You can get a or b back if you have the other value available:

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

For example if a = 5, b = 3 (and thus c = 6 as you mentioned) you get:

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

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...