hi guys,

i'm learning C at the moment and i'm writing a little program which needs as input a decimal value, and by choice, converts it to octal, hex, or the ascii character.

it would be nice to learn, and to add to the program, the option of converting the decimal value to binary.

but my problem is, i know how to convert decimal to binary by head, but not how to do this if the decimal value is a variable (in this case an integer)

here is what i've got so far, its not that fancy coding, but hey, i'm learning
#include <stdio.h>

int main()
{
int a, b, ask;

printf("\nThis is a number converter.\n");
printf("Enter a decimal value: ");
scanf("%d",&ask);
printf("\nWhich output do you like?\n");
printf("1 = hex, 2 = octal, 3 = character :");
scanf("%d", &a);

switch(a)
{
case 1:
printf("Do you want a leading \"0x\" for the output?");
printf("\nyes = 1, no = 2 : ");
scanf("%d",&b);
switch(b)
{
case 1:
printf("\nThe value %d has the hexadecimal value of 0x%x\n\n",ask,ask);
break;
case 2:
printf("\nThe value %d has the hexadecimal value of %x\n\n",ask,ask);
break;
default:
printf("\nThis is not a valid option\n");
break;
}
break;
case 2:
printf("\nThe value %d has the octal value of %o\n\n",ask,ask);
break;
case 3:
printf("\nThe value %d has the character value of %c\n\n",ask,ask);
break;
default:
printf("\nThis is not a valid option\n");
return 0;
}
return 0;
}
let's say i've inputted the value 32, how can make it 0100000 without having to make a table in the program, which looks up the value?

is there an standard option for in C, like %x gives the hex value??

or do i need to write a function?

and if so, how would i do this?



thanks in advance for the replies....