def loop2(b):
    x = 0
for c in b:
    x <<= 8
x |= c
return x

def numpily(b):
    n = np.array(list(b))
p = 1 << np.arange(len(b) - 1, -1, -1, dtype=object)
return np.sum(n * p)
Convert variable-sized byte array to a integer/long