First time here? Checkout the FAQ!
x
menu search
brightness_auto
more_vert

What are bitwise and logical operators in C ?

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike

1 Answer

more_vert
 
verified
Best answer

Bitwise Operator :

These operators work bitwise on a data.
They perform different operations on bits of a data
like AND, OR, EXOR and NOT.
The operators are listed below :

  1. ~ to perform bitwise NOT operation.
  2. & to perform bitwise AND operation.
  3. | to perform bitwise OR operation.
  4. ^ to perform bitwise EXOR operation.
  5. << to perform bitwise left shift operation.
  6. >> to perform bitwise right shift operation.
    These operators are use to perform bitwise binary
    operations on the data.
    As we have addition, subtraction operations in
    decimal data for performing arithmetic operations;
    similarly AND, OR, NOT are basic bitwise operations
    on the binary data.

Logical Operators :

Logical operators follow the same truth table as
for the bitwise operators; but they are used to
check conditions instead of performing
operations on a data.
The logical operators are AND and OR. The
symbols used for these operators in C are &&
and || respectively.
For example a statement
y > 5 && y < 10; will result in “true” i.e. 1 if the value of y is greater than 5 AND less than 10, else it will result in false i.e. 0. Another example a statement y > 5 || y==2;
will result in “true” i.e. 1 if the value of y is
greater than 5 OR equal to 2, else it will result
in false i.e. 0.
Logical operators will be understood in more
details with the expressions and program
examples followed by this section.

thumb_up_off_alt 0 like thumb_down_off_alt 0 dislike
...