Solving Bitwise Arithmetic: What Trick Makes it Easy?

  • Context:
  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Arithmetic
Join the discussion
Registration is free. Ask a follow-up in this thread, or start your own.
2 replies · 2K views
tmt1
Messages
230
Reaction score
0
1234567 ^ 7 ^ ~~1234567

5 & (12345678 ^ ~~ 12345678)

My prof said there is an easy way to solve these as there is a trick to it. Does anyone know what trick is being referred to?
 
Physics news on Phys.org
tmt said:
1234567 ^ 7 ^ ~~1234567

5 & (12345678 ^ ~~ 12345678)

My prof said there is an easy way to solve these as there is a trick to it. Does anyone know what trick is being referred to?

The "tricks" here are just the basic properties of bitwise arithmetic, namely that ~~x is equivalent to x (negating a bit, and then negating it again, gives you back the original bit) and x ^ x is equivalent to 0 (look at the truth table for exclusive-or). Finally, ^ is commutative. Does that make it easier?