Decimal Equivalent of Gray Code and its Inverse | CPP Program to convert given decimal number of gray code into its inverse in decimal form ; Function to convert given decimal number of gray code into its inverse in decimal form ; Taking xor until n becomes zero ; Driver Code
#include <bits/stdc++.h> NEW_LINE using namespace std ; int inversegrayCode ( int n ) { int inv = 0 ; for ( ; n ; n = n >> 1 ) inv ^= n ; return inv ; } int main ( ) { int n = 15 ; cout << inversegrayCode ( n ) << endl ; return 0 ; }