Bitwise operators in C: Logic of Exclusive OR or XOR

As the name suggests bitwise operators are used for operation on bits. They are used for testing and shifting of actual bits in a byte or word. It is used for int and char data types. I cannot be used for float and double and other complex data types. Here are the bitwise operators:

Bitwise Operators Function
| OR
^ Exclusive OR (XOR)
~ One’s complement (NOT)
>> Shift right
<< Shift left

Here’s a truth table to see the logic of XOR: Output a^b is true only when one input a or b is true.

a b a^b
a b a^b
0 0 0
1 0 1
1 1 0
0 1 1

Bitwise operators are generally used in device drivers, disk file routines and printer routines.

Leave a Reply