Gray to Binary and Binary to Gray conversion | Java Program for above approach ; Driver code
public class Main { public static int greyConverter ( int n ) { return n ^ ( n >> 1 ) ; } public static void main ( String [ ] args ) { int n = 3 ; System . out . println ( greyConverter ( n ) ) ; n = 9 ; System . out . println ( greyConverter ( n ) ) ; } }