• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

& and | on same number

 
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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?
 
Wanderer
Posts: 18671
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 = ?
 
Ranch Hand
Posts: 3061
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Jasper Vader
Ranch Hand
Posts: 284
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
ohhh... i see... Zero!

thanks jim and layne!
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic