+3

What are left and right shift operators in C++

Left right shift operators in C++ need a detailed explanation on that . How these are supposed to work ,where to use them and why https://code.sololearn.com/cIbb0m8N5PFQ/?ref=app

10/13/2019 3:47:21 PM

Ddhruv

4 Answers

New Answer

+2

If you need a detailed explanation i guess you are better off searching some tutorial site; there might be quite a lot of ground to cover depending on your current level of understanding the nitty-gritty details of a computer ☺ There may also be lessons on bitshift operators on here, I haven't checked yet. The gist would be that "n << m" shifts the bits of n collectively m positions to the left filling up on the right with zeros. Right shift works similarly but you have to distinguish between a pure binary shift and arithmetic right shift. The use is often a quick way to multiply (left shift) or divide by (right shift) powers of two; in fact: n << m is n * 2^m. Multiplication and especially division are expensive operations. Shifting bits is fast in comparison. These operators appear where a lot of those kinds of multiplications and divisions occur in order to speed up the computation. More use case may apply ☺ Maybe I find a lesson link on here ... Here is one: https://www.sololearn.com/learn/4086

+2

Thanks a lot Miika it's very helpful.

+2

Ya I saw that you have shared it's link I will study that lesson surely Thanks a lot again .

+1

You're welcome ☺ There is also a lesson on the left shift operator. They are subsumed under the user added course "bit operations"