left shift << and right shift >> operators in c++

by Ramya 2013-10-05 18:58:22

Bit Shift Operators in C++:

There are two types of bitwise operators:

* left shift << -> left shift a value x by y bits (ie, x << y)

* right shift >> -> shift x right by y bits (ie, x >> y),
Note: highest bit in x is one

To calculate right-shift expression, use

x >> y is x / 2y


eg,

-1>>4 = -1/(2)4 = -0.0625


To calculate the value of left-shift expression, use

x << y is x * 2y


eg,

-1<<4 = -1*(2)4 = -16
969
like
0
dislike
0
mail
flag

You must LOGIN to add comments