This week's book giveaway is in the OO, Patterns, UML and Refactoring forum. We're giving away four copies of Refactoring for Software Design Smells: Managing Technical Debt and have Girish Suryanarayana, Ganesh Samarthyam & Tushar Sharma on-line! See this thread for details.
2 & 2 will always be two. ditto for 2 | 2. etc etc ... 150 & 150 will always be 150 ditto for 150 | 150 ... but what about if the number were negative... still no change to the original value methinks... but no such simple rule would be for an exclusive or operation?
but what about if the number were negative... still no change to the original value methinks... Correct. but no such simple rule would be for an exclusive or operation? There's actually a very simple rule for the result of x ^ x. Try it with an example - what's 41 ^ 41? In binary: 00101001 ^ 00101001 = ?
You can try two simpler examples: 0 ^ 0 = ? 1 ^ 1 = ? Since these are the only two possible values for a given bit, the answers to the above equations will help you find the rule you are looking for. HTH Layne