Bitwise Operators

<<  is bitwise left shift operator  .It shifts the binary equivalent buy specified number of bits to left.If we shift  by one bit to left then it is equivalent to multiplying a number by 2.

>> is bitwise right shift operator.It shifts the binary equivalent buy specified number of bits to right.If we shift  by one bit to left then It is equivalent to dividing a number by 2.

ex:-

int x=24,y,z;

y=x>>1;

z=x<<1;

then y=12 and z=48…

So we can use these operators in place of %(mod) and /(div) operators….

Suppose we want to find remainder and divisor when we divide a number by 2 thn

d=n>>1;                        //gives the divisor

r=n-((n>>1)<<1);                 //gives the remainder

Advertisements

Leave a comment

Filed under PROGRAMMING

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s