@@ -0,0 +1,539 @@
+package com.coderevisited.bits;%0A%0Apublic class GrayCodeConversion%0A%7B%0A%0A    public static void main(String%5B%5D args)%0A    %7B%0A        int n = binaryToGrayCode(10);%0A        System.out.println(%22binary to gray %22 + n);%0A        System.out.println(%22gray to binary %22 + grayToBinary(n));%0A    %7D%0A%0A    public static int binaryToGrayCode(int n)%0A    %7B%0A        return (n %3E%3E 1) %5E n;%0A    %7D%0A%0A    public static int grayToBinary(int n)%0A    %7B%0A        for (int mask = n %3E%3E 1; mask != 0; mask = mask %3E%3E 1) %7B%0A            n = n %5E mask;%0A        %7D%0A        return n;%0A    %7D%0A%7D%0A

binary to Gray Code. gray code to binary