Binary to Gray number..


#include<stdio.h>
#include<stdlib.h>

int main()
{
    int n,i;
    scanf("%d",&n);
    puts("binary representation of the number is: \n");
    for(i=31;i>=0;i=i-1)
    {
        printf("%d",(n>>i)&1);
    }
    int gray = n^(n>>1);
    puts("\ngray number of the entered number is: \n");
    printf("%d",gray);
    puts("and binary representation of the gray number is: \n");
    for(i=31;i>=0;i=i-1)
    {
        printf("%d",(gray>>i)&1);
    }

}

Comments

Popular Posts