canonical bit-manipulating problem