sir i dont understand what will happen in left shift?
Bitwise left shift
Hello @guptaaman155,
What is Bitwise left shift operator?
All the bitwise operators operate on the binary representation of a number.
Bitwise left shift operator, as the name suggests, shifts the bits(i.e 0 or 1) present in the binary representation towards left by 1 position and insert a 0 at the rightmost position. Here, the leftmost bit before applying the operator gets lost after applying it.
How many operands does it require?
It requires 2 operators, first is the number you wants to shift and second is the number specifying how many shifts you want to perform.
Let’s understand this using an example:
a = 5 (binary representation: 00000101)
b =2 (no. of shifts)
print(a<<1); 00001010 , left shift by one position
print(a<<b); 00010100 , left shift by two positions.
You have to understand the following statement by yourself. It’s a small task.
left shifting an integer “a” with an integer “b” (a<<b) is equivalent to multiplying a with 2^b (2 raise to power b).
Hope, this would help.
If you still have doubts, feel free to ask.
Give a like if you are satisfied.