Added the link for a better solution
Gray Code