Bitwise Operators

As we know all data in computers are stored in the form of 0 and 1.So to manipulate our data in bit level bitwise operators are used. Bitwise operators can only operate with integers.

In C following are the bitwise operators:

op

Bitwise AND Operator:

and

Bitwise AND operator is a binary operator.Bitwise AND operators requires two operand to perform to perform bit manipulation on its operand.This operator gives results by comparing each bit of both operand.If the  value of both the operand will be 1then only the resulting bit of this operator will be 1 otherwise it will be 0.

Bitwise OR operator:

or

Bitwise OR operator is also binary operator which requires two operand to perform bit manipulation .Resulting bit of this manipulation will be 0 if the value of both operands will be 0 otherwise it will be 1.

Bitwise XOR Operator:

xor

Bitwise operator is also a binary operator which requires two operand to perform its bit manipulation. The resulting bit of this manipulation will be 1 if  the value of both operand will be different otherwise it will be 0.

One’s Complement Operator:

one

 

 

 

This operator requires one operand to perform bit manipulation. Hence this operator is unary operator.This operator alters the value of its operand from 1 to 0 and 0 to 1.

Bitwise left shift operator:

This operator is used to shift the bits  left. It requires two operand to shift the bit.

Syntax:

example

Have a look bit pattern given below:

Bit pattern of x(x is a number)

l l2

 

Left operand is the operand whose bits are  to be shifted and right operand indicates the number of bits to be shifted. On shifting the bits left equal number of bits from left side will be lost and equal number of bits from  right side will be vacated and those bit will be filled up with the value 0.

Bitwise Right Shift Operator:

This operator is used to shift the bit right .It also requires two operand to shift  bit  value.

Syntax:

Example:

l3
l4

 

On shifting the bits right equal number of bits will be vacated in left and equal number of bit from right will be lost.the vacated left bit will be filled by 0 .

Note:

It should be kept in mind while using shift operators(<< and >>) right side operand never should be negative .
There are many site which provides information related to the Programming please click here for more details.

3 thoughts on “Bitwise Operators”

  1. Pingback: buy fifa points

Leave a Reply