[New-bugs-announce] [issue42720] << operator has a bug
report at bugs.python.org
Tue Dec 22 14:00:22 EST 2020
New submission from Nandish <lbnandish at gmail.com>:
I verified the following on both Python 2.7 and Python 3.8
I did print(100<<3) Converting 100 to Binary gives 1100100. What I did is I droped the first 3 bits and added 3 bits with the value '0' at the end. So it should result as 0100000, and I converted this to Decimal and the answer was 32.
For my suprise when I executed print(100<<3) the answer was 800. I was puzzled. I converted 800 to Binary to check whats going on. And this is what I got 1100100000.
If you see how 800 was Python answer, they did not shift or drop the first 3 bits but they added value '0' to last 3 bits.
Where as print(100>>3) , worked perfect. I did manual calculation and cheked the print result from python. It worked correctly. Dropped last 3 bits and added value '0' to first 3 bits.
Looks like (100<<3) , left shift operator has a bug on Python.
title: << operator has a bug
versions: Python 3.8
Python tracker <report at bugs.python.org>
More information about the New-bugs-announce