J Freebird
J Freebird

Reputation: 3910

Python: Get the lower bits of an integer

I have a Python program that gets some integers from MySQL. The field in the database is of type INT and length 10, unsigned. I wonder when I retrieved such a integer in a Python program, what its size will be? And then what should I do to get only the lower 16 bits (it's supposed to be 32-bit)?

Upvotes: 0

Views: 2755

Answers (1)

num <- from db
last_16bit = 0
for i in range(16):
    last_16bit = 2*last_16bit + num%2
    num= num>>1

Upvotes: 1

Related Questions