Thursday, January 14, 2010

11.2.2 THE LOGICAL BITWISE OPERATORS

There are three logical bitwise operators: bitwise and (&), bitwise or (|), bitwise exclusive or (^). Each of these operators requires two integer-type operands.The operations are carried out independently on each pair of corresponding bits within the operands.Thus, the least significant bits (i.e. the rightmost bits) within the two operands will be compared. The results of these comparisons are:
1. A bitwise and expression will return a 1 if both bits, have a value of 1 (i.e., if both bits are true). Otherwise,  it will return a value of 0.
2.  A bitwise exclusive or expression will return a 1 if one of the bits has a value of 1 (i.e., if one bit is true, the other is false). Otherwise,  it will return a value of 0.
3. A bitwise or expression will return a 1 if one or more bits, have a value of 1 (i.e., if one or both bits are true). Otherwise,  it will return a value of 0.

The results are summarized in the following table.


b1

b2

b1&b2

b1^b2

b1|b2

1

1

1

0

1

1

0

0

1

1

0

1

0

1

1

0

0

0

0

0

No comments:

Post a Comment