0
What does << mean in Python??
X=5 print(x<<2) Output = 20
9 ответов
+ 4
x << y
Moves all 1s in x's bit format to left by y steps.
50 << 3
50 equals 110010 in binary.
= 000110010 << 3
= 001100100 << 2
= 011001000 << 1
= 110010000
110010000 = 400
That's why 50 << 3 would equal 400
+ 3
So in other words, 50 * (2*2*2) for 3 bits?
+ 2
Troy Yes, bit operators can also be faster than basic operators.
There is also >> which differs by moving bits y steps right instead.
50 >> 3 = 6
+ 2
np
0
This is the same as multiplying x by 2**2 (shifting of 2)
0
Thank you!
0
Thank you Seb!
0
Thank you!!