Bitwise operators with signed numbers

Hello Team,

Could you please also explain how the bitwise operators work with signed numbers, especially the left shift and right shift operators. For example, what will be the result of: -2 << 2?

this will give you -8, that is
-2 -> -10
-8 -> -1000

I am getting -42 as output of -2 << 2

My question is not specific to this example. My question is in general how to handle << and >> operators with signed numbers

See this


They work the same as they work with int.

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.