Solving Bitwise Arithmetic: What Trick Makes it Easy?

  • Context: MHB 
  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Arithmetic
Click For Summary
SUMMARY

The discussion focuses on solving bitwise arithmetic expressions using fundamental properties of bitwise operations. Key insights include the equivalence of ~~x to x, the property that x ^ x equals 0, and the commutative and associative properties of the XOR operator (^). These principles simplify the evaluation of expressions like 1234567 ^ 7 ^ ~~1234567 and 5 & (12345678 ^ ~~12345678).

PREREQUISITES
  • Understanding of bitwise operations
  • Familiarity with the XOR operator (^) in programming
  • Knowledge of logical negation (~~) in binary arithmetic
  • Basic concepts of truth tables
NEXT STEPS
  • Study the properties of bitwise operations in programming languages like Python or C++
  • Learn about truth tables and their application in logical operations
  • Explore advanced bit manipulation techniques for optimization
  • Investigate common use cases of bitwise arithmetic in algorithms
USEFUL FOR

Computer science students, software developers, and anyone interested in optimizing algorithms through bitwise operations.

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?
 
Technology 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?
 
Bacterius said:
Finally, ^ is commutative.

Nitpicking. We also need that ^ is associative, which it is. ;)
 

Similar threads

  • · Replies 93 ·
4
Replies
93
Views
6K
  • · Replies 15 ·
Replies
15
Views
10K
Replies
4
Views
3K
  • · Replies 1 ·
Replies
1
Views
2K
  • · Replies 16 ·
Replies
16
Views
2K
Replies
31
Views
6K
Replies
16
Views
4K
  • · Replies 3 ·
Replies
3
Views
2K
  • · Replies 5 ·
Replies
5
Views
2K
  • · Replies 2 ·
Replies
2
Views
639