Filter by Tags

Left and right shift operators

Votes

0

0 0

Explain the working of left and right shift operators in C with an example.

Open E-School
Posted on : Wed, Jun 14, 2017
Views : 142
Comments

Ask Question

If you want to ask question you must LogIn or SignUp
Login SignUp

Answers (2)


0

Left shift operator(<<) shift the bits of a number to the left side.

To use Left shift operator put variable at the left side of operator and on the right side of operator put the number bits you want to shift to right.

Eg. int c = 3;

printf("%d",c << 2);

output: 12

Explanation: 3 = 0011

now 2 bits to shift to the right then

0011 -> 1100

1100 is equals to 12 which is the output.

 

Right shift operator (>>) works the same as left shift operator but it only shift the bits rowards the right side.

eg. 12 = 1100

After appling right shift operator it will become 0011 which is equal to 3.

Sahil Gaba
Wed, Jun 14, 2017
Loading...
Comments

Edit Answer

Submit

0

Left Shift- Left shift operator is a bitwise operator which shifts bits of a number in left direction. If a number is left shifted by 1 bit then it becomes double its value. e.g. if we left shift 4 by one bit then it becomes 8.

Right Shift- Right shift is a bitwise operator in C which shifts bits of a number in the right direction. If a number is shifted by 1 bit then it becomes half its value. e.g. if we right shift 4 by ine bit, then it becomes 2.

The "<<" operator is for left shift and ">>" is for right shift

Apurva Thakker
Wed, Jun 14, 2017
Loading...
Comments

Edit Answer

Submit
This answer will permanently deleted. Do you really want to delete this Answer ?
To Add your Answer Please
LogIn | SignUp

Quick Links

E-Magazines

@

Total Followers
Study Group Created
Study Group Joined
Following Teacher
Following Organization
Blog Articles Added
Questions Asked
Questions Answered
Jobs Posted
Total Members in Group
Questions asked by members
Tasks added in this Group

Please wait..

Ok

Login to Open ESchool OR Create your account    Login   SignUp