MHB Solving Bitwise Arithmetic: What Trick Makes it Easy?

  • Thread starter Thread starter tmt1
  • Start date Start date
  • Tags Tags
    Arithmetic
AI Thread Summary
The discussion focuses on solving bitwise arithmetic expressions, specifically 1234567 ^ 7 ^ ~~1234567 and 5 & (12345678 ^ ~~12345678). The key trick mentioned involves understanding basic properties of bitwise operations: negating a bit twice (~~x) returns the original value, and the exclusive-or operation (^) has properties such as x ^ x = 0 and being both commutative and associative. These properties simplify the expressions and make solving them easier.
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. ;)
 
Dear Peeps I have posted a few questions about programing on this sectio of the PF forum. I want to ask you veterans how you folks learn program in assembly and about computer architecture for the x86 family. In addition to finish learning C, I am also reading the book From bits to Gates to C and Beyond. In the book, it uses the mini LC3 assembly language. I also have books on assembly programming and computer architecture. The few famous ones i have are Computer Organization and...
I have a quick questions. I am going through a book on C programming on my own. Afterwards, I plan to go through something call data structures and algorithms on my own also in C. I also need to learn C++, Matlab and for personal interest Haskell. For the two topic of data structures and algorithms, I understand there are standard ones across all programming languages. After learning it through C, what would be the biggest issue when trying to implement the same data...
Back
Top