Fix #40

Improve code portability to deal with cases where:
- right shift is always unsigned
- size of int is not 32 bits