Newbie need help in C Programming

Status
Not open for further replies.

DigitalBoy

New Member
Hi all,

Long time reader, first time poster.

I would like to know if there's a code to convert an integer to binary directly in C Language, or do I have to mod (%) the integer until it is 0? ie. 6%2=0, 3%2=1, 1%2=1, then the binary equivelant of 6 is 110.

Thanks in advance.
 
You will have to program your own function for that. I'd recommend doing shift and testing for even or odd numbers to determine the rightmost bit.

Good luck!
 
converting integer to binary

hi there,

i guess there is no such method directly to convert integer to binary.

for(i=num;i>0;i=i/2)
{
if(i==1)
{
printf(%d,i);
break;
}else
{
i=i%2;
printf(%d,i);
}
}

then u can revese and print.

hope his will help,
Rajeev
 
Status
Not open for further replies.
Cookies are required to use this site. You must accept them to continue using the site. Learn more…