Explain shift operators in detail. Pratik bhaiya didn’t explained it how it works. So explain in detail. Also explain bitwise operators in detail.
Doubt in shift operators
hello @Shivam01
In a binary, or base 2
, numbering system, we can represent integers based on their internal sequence of bit values, as follows
1 1
2 10
3 11
4 100
5 101
6 110
7 111
8 1000
9 1001
The shift operators, <<
(shift left), and >>
(shift right), take two integers as operands. They return the result of shifting the bits of the left operand by the number of positions specified by the right operand. The left shift operator shifts bits to the left, and the right shift operator shifts bits to the right.
Consulting the list of integers and their bit representations above, we can predict that …
4 >> 1
… will shift the 1
in 4
's bit representation by 1
position to the right, resulting in 010
, or, more succinctly, 10
. Looking at the chart again, we see that 10
is the bit representation for 2
. So, the result is 2
read more about them from here -> https://www.geeksforgeeks.org/left-shift-right-shift-operators-c-cpp/
bitwise operator-> https://www.geeksforgeeks.org/bitwise-operators-in-c-cpp/
I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.
On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.