[issue42720] << operator has a bug

2020-12-22 Thread Nandish


New submission from Nandish :

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 010, 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 
110010.

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 
<https://bugs.python.org/issue42720>
___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue42720] << operator has a bug

2020-12-22 Thread Nandish

Nandish  added the comment:

I took print(100>>3), I dropped last 3 bits and added value ‘0’ to first 3
bits. Both manual calculation and python result was correct.

How can << shit operator and >> shit operator work differently , with
different logic ?

Thanks
Nandish

On Wed, Dec 23, 2020 at 12:54 AM Eric V. Smith 
wrote:

>
> Eric V. Smith  added the comment:
>
> Why do you think the first 3 bits should be dropped? That's not the
> documented behavior of <<.
>
> --
> nosy: +eric.smith
>
> ___
> Python tracker 
> <https://bugs.python.org/issue42720>
> ___
>

--

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