+ 11
Why the output is 20???
11 Réponses
+ 7
Please read this, it should contain what you need in order to understand this.
https://www.sololearn.com/learn/4070/?ref=app
+ 9
The binary pattern of 5 is
00000101.
If you shift this two steps to the left, it becomes 00010100.
And that is 20.
If this is not clear to you, you should read the material here on Sololearn about how binary numbers and operators work.
+ 9
Thanks everyone! I didn't knew that! 🐟
+ 6
If we do
x=5
print(x>>2)
OUTPUT IS : 1
why????
+ 5
00000101 shifted to the right once becomes 00000010. The right side 1 drops out.
+ 4
What is the use of <<???
+ 4
But this is a binary of 2???
+ 4
Anhjje then answer should be 25 not 20....
+ 4
Thanks everyone🙂🙂🙂
+ 4
Returns x with the bits shifted to the left by y places (and new bits on the right-hand-side are zeros). This is the same as multiplying xby 2**y.
IN YOUR QUESTION
X=5
PRINT(x<<2)
So,it will multiply 5 with 2^2
That equals ..5 *4=20
Hope it helps..
HAPPY CODING😀😀
- 1
python is a general purpose, object oriented, high level programming language