py: Fix bug with right-shifting small ints by large amounts.

Undefined behavior in C, needs explicit check.