Hey Guys,
Just a quick querry regarding some code i wrote to convert a decimal to hexadecimal, the code runs perfectly fine except for one hickup, it prints it backwards which is what I would expect. I was just wondering if there was a way I could flip the output. Any help would be greatly appreciated.
Code:
printf("Enter a decimal :");
scanf("%d", &x);
printf("\n");
do{
if(x%16 < 10)
{
printf("%d", x % 16);
x = x>>4;
}
else if(x%16 >=10)
{
if(x % 16 == 10)
printf("A");
else if(x % 16 == 11)
printf("B");
else if(x % 16 == 12)
printf("C");
else if(x % 16 == 13)
printf("D");
else if(x % 16 == 14)
printf("E");
else if(x % 16 == 15)
printf("F");
x=x>>4;
}
if(x<16)
printf("%d", x);
}while(x>1);
Regards Sean