C Programming Bitwise Operators



This tutorial will explain you the basic idea behind C Programming Bitwise Operators. Why bitwise operators are introduced in C Programming.

C Programming Bitwise Operators

Byte Level Operations

Till now we have seen all the operators uses variables and constants for expression solving and they operate all the calculations at byte level. like –

res = num1 + num2;

In the above line all are integers which requires two/four/eight bytes memory in C programming depending on the compiler.

Bit Level Operations

  1. Sometimes it become mandatory to consider data at bit level.
  2. We have to operate on the individual data bit. We also need to turn on/off particular data bit during source code drafting, at that time we must use bitwise operator for doing our task easier.
  3. C Programming provides us different bitwise operators for manipulation of bits.
  4. Bitwise operators operates on Integer,character but not on float,double
  5. Using bitwise operators we can manipulate individual bits easily
  6. C programming supports 6 bitwise operators –

List of bitwise operators

OperatorName of Operator
~One’s Compliment
>>Right Shift
<<Left Shift
&Bitwise AND
|Bitwise OR
^Bitwise XOR

Bitwise operator rules

Input BitsANDORXOR
00000
01011
10011
11110

Summary :

OperatorUsage
One's compliment operatorUsed to turn a bit on/off
AND bitwise operatorUsed to mask particular part of byte
Left shift bitwise operatorUsed to shift the bit to left
Right shift bitwise operatorUsed to shift the bit to right