Skip to content

Instantly share code, notes, and snippets.

@vikhyat
Created December 10, 2014 04:40
Show Gist options
  • Save vikhyat/15e02173c3d20b981205 to your computer and use it in GitHub Desktop.
Save vikhyat/15e02173c3d20b981205 to your computer and use it in GitHub Desktop.
#include <stdio.h>
int gray_decode(int n) {
int p = n;
while (n >>= 1) p ^= n;
return p;
}
int main() {
int t, c;
scanf("%d\n", &t);
while (t--) {
scanf("%d\n", &c);
printf("%d\n", gray_decode(c));
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment