Linsu Han
Linsu Han

Reputation: 165

Is bit shift same as integer multiplication/divison in Python?

I read somewhere that they are different when the number is negative, but I did a quick test and it appears they are equivalent, at least in python?

for i in range(-1000, 1000):
    assert(i >> 1 == i // 2)
    assert(i << 1 == i * 2)

Upvotes: 0

Views: 54

Answers (0)

Related Questions