Encode State Machines using gray code