added gray code conversion