Solution for some bit manipulation problems