New submission from Nandish <lbnand...@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.

----------
messages: 383599
nosy: Nandish
priority: normal
severity: normal
status: open
title: << operator has a bug
type: behavior
versions: Python 3.8

_______________________________________
Python tracker <rep...@bugs.python.org>
<https://bugs.python.org/issue42720>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com

Reply via email to