Rename bittwiddling functions and fix shifting bug