Here is a snippet of Verilog code that converts an 8-bit binary value to Grey code. It makes use of Exclusive-OR to to generate Grey values.
grey_value[0] = ^binary_value[1:0];
grey_value[1] = ^binary_value[2:1];
grey_value[2] = ^binary_value[3:2];
grey_value[3] = ^binary_value[4:3];
grey_value[4] = ^binary_value[5:4];
grey_value[5] = ^binary_value[6:5];
grey_value[6] = ^binary_value[7:6];
grey_value[7] = binary_value[7];
Here is a snippet of Verilog code to convert from Grey to Binary using an 8-bit Grey value,
binary_value[7] = grey_value[7];
binary_value[6] = ^grey_value[7:6];
binary_value[5] = ^grey_value[7:5];
binary_value[4] = ^grey_value[7:4];
binary_value[3] = ^grey_value[7:3];
binary_value[2] = ^grey_value[7:2];
binary_value[1] = ^grey_value[7:1];
binary_value[0] = ^grey_value[7:0];