Q:

Python 2.7 variable type stays as int32 instead of converting to long

I'm trying to decode a list of boolean values into numbers via bitwise shifting operations in a for loop. This is a simplified example of my code:
import numpy as np
k = 0
m = np.full((1, 32), True, dtype=bool)    # example list
n = m[0]
for i in n:
    k = k << 1 | i

print (k)

However, k returns as -1 instead of 4294967295. Running this in a debugger shows that k is of type int32. Is there anyway to force k to be a long type instead? Or is there an alternative way to decode my list of booleans. The code should handle up to 128 bits. I'm wondering if this only happens in a for loop since shifting more than 32 bits outside of the loop seem to work fine.
Using k = 0L gives correct value for my example code, but it only changes the type to int64 and does not work for boolean lists longer than 64.

A:

After some fiddling about I got my code working the way I wanted. Turns out all I had to do was cast the bitwise operation into a long type. Problem seems to be that the bitwise operator kept returning int32 or int64 types. This is only for Python 2.7
import numpy as np
k = 0
m = np.full((1, 129), True, dtype=bool)    # example list
n = m[0]
for i in n:
    k = long((k << 1 )| i)

print (k)    # should give '680564733841876926926749214863536422911'

