• 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

K & B boolean Question

 
Ranch Hand
Posts: 103
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello Folks,

somebody Can explaint how the line1 become false and line2 become true.

Thanks, Raghu.K


 
author
Posts: 23951
142
jQuery Eclipse IDE Firefox Browser VI Editor C++ Chrome Java Linux Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This question has appeared on this forum before -- just use the search link above to look for either "SSBool" or "dokey".

Basically... the key to getting the answer is an understanding that the bitwise AND operator has a higher precedence than the bitwise OR operator.

Henry
[ September 20, 2006: Message edited by: Henry Wong ]
 
Ranch Hand
Posts: 42
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi,

Its simple you evaluate from left to right and replace every expression with its value you'll get the answer.

line 1:

if (b1 & b2 | b2 & b3 | b2)

if( true & false | false & true | false) became
if(false | false & true | false) after evaluating true & flase to false. Then that became
if(false & true | false) after evaluating false | false to false. After that false & true gave false then false | false gave false as a result.

For Line 2:
Its just performing line 1 result | b1. b1 is true. hence false (result of line 1) | true yields true.


I think you are clear now.
 
Greenhorn
Posts: 16
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
"|" means or,and "&" means and!
 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Henry Wong:
This question has appeared on this forum before -- just use the search link above to look for either "SSBool" or "dokey".

Basically... the key to getting the answer is an understanding that the bitwise AND operator has a higher precedence than the bitwise OR operator.

Henry

[ September 20, 2006: Message edited by: Henry Wong ]



Simplest answer is it is all in operator precedence!
 
reply
    Bookmark Topic Watch Topic
  • New Topic