Storing "binary" data type in C program
- by puchu
I need to create a program that converts one number system to other number systems. I used itoa in Windows (Dev C++) and my only problem is that I do not know how to convert binary numbers to other number systems. All the other number systems conversion work accordingly. Does this involve something like storing the input to be converted using %?
Here is a snippet of my work:
case 2:
{
printf("\nEnter a binary number: ");
scanf("%d", &num);
itoa(num,buffer,8);
printf("\nOctal %s",buffer);
itoa(num,buffer,10);
printf("\nDecimal %s",buffer);
itoa(num,buffer,16);
printf("\nHexadecimal %s \n",buffer);
break;
}
For decimal I used %d, for octal I used %o and for hexadecimal I used %x. What could be the correct one for binary? Thanks for future answers!