cpp implementation of Gray Code