Changed handling of bit

Reworked to use bit shifting rather than mod/division