added functions to generate gray code, grouping bits and main function.