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?

2
  • @li.davidm, Thanks! I got it! What should I do with this question, delete it? Commented Aug 3, 2015 at 2: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. Commented Aug 4, 2015 at 21:49

0

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.