correct handling of bit shifting