This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes Beginning Java and the fly likes & and | on same number Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "& and | on same number" Watch "& and | on same number" New topic
Author

& and | on same number

Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
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?


giddee up
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
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 = ?


"I'm not back." - Bill Harding, Twister
Layne Lund
Ranch Hand

Joined: Dec 06, 2001
Posts: 3061
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


Java API Documentation
The Java Tutorial
Jasper Vader
Ranch Hand

Joined: Jan 10, 2003
Posts: 284
ohhh... i see... Zero!

thanks jim and layne!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: & and | on same number
 
Similar Threads
Si Brewster please read!!
Special doin's at JavaRanch
Security Forum?
A BIG 'OL THANK YOU TO MARILYN FOR NITPICKING MY CODE
uh,huh