Newbie -- bitwise shifts
Jp Calderone
exarkun at intarweb.us
Wed Feb 4 16:46:11 EST 2004
On Wed, Feb 04, 2004 at 01:24:00PM -0800, gbblob wrote:
> Can someone please explain to me why left shits are equivalent to
> multiplication and right shifts equivalent to devision? This seems
> backwards to me.
>
> e.g.
>
> 15 is binary 1111
> if I shift this left 2 bits I get 11
>
> however in Python 15<<2 = 60 ?!
>>> from binary import binary
>>> binary(15)
'1111'
>>> binary(15<<2)
'111100'
>>> binary(15>>2)
'11'
Jp
More information about the Python-list
mailing list