1
$\begingroup$

I want to take two numbers, say 200 and 101, and transform them into their binary form. Then XOR them together and transform the result back into the decimal form. The result in this case should be 173.

I tried to play with the BaseForm[200, 2] and BaseForm[101, 2]. However, I cannot work with the result. I also tried the operator Xor, for example, Xor[1, 1], but it returns False instead of 0.

Any idea?

$\endgroup$
1
  • 1
    $\begingroup$ BitXor is intended for this. $\endgroup$ Commented Oct 29, 2023 at 21:56

1 Answer 1

2
$\begingroup$
a = 200; b = 101; ceiling = Max@(Ceiling@Log2@# & /@ {a, b}) abin = IntegerDigits[a, 2, ceiling] bbin = IntegerDigits[b, 2, ceiling] FromDigits[BitXor[abin, bbin], 2] 

173

$\endgroup$
2
  • 1
    $\begingroup$ BitXor[200, 101] would also do it but sometimes things get more involved with the masking going on. $\endgroup$ Commented Oct 29, 2023 at 15:20
  • 1
    $\begingroup$ Thank you I've got it. $\endgroup$ Commented Oct 29, 2023 at 16:47

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.