0

My Python version is

'3.4.2 (v3.4.2:ab2c023a9432, Oct 6 2014, 22:16:31) [MSC v.1600 64 bit (AMD64)]'

I have some work that need bit shift operation but I found in Python it works strange.

The problem is I can not limit my number's length. In JS:

1 << 63 = -2147483648

However, in Python:

1 << 63 = 9223372036854775808

Further more, in JS we have >>> operator which ignore negative numbers.

I know in Python

A right shift by n bits is defined as floor division by pow(2,n). A left shift by n bits is defined as multiplication with pow(2,n).

But how to simulate these js/c++ bit operations in Python?

Donald
  • 633
  • 5
  • 16
PaleNeutron
  • 2,543
  • 4
  • 25
  • 43
  • @li.davidm, Thanks! I got it! What should I do with this question, delete it? – PaleNeutron Aug 03 '15 at 02:19
  • no need to delete it, hopefully it'll help someone else. You could also answer your own question. I think I'll also flag this as a duplicate. – li.davidm Aug 04 '15 at 21:49

0 Answers0