Continue to Site

Welcome to our site!

Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

  • Welcome to our site! Electro Tech is an online community (with over 170,000 members) who enjoy talking about and building electronic circuits, projects and gadgets. To participate you need to register. Registration is free. Click here to register now.

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. :oops:
 
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! :D
 
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 :D
 
Status
Not open for further replies.

Latest threads

New Articles From Microcontroller Tips

Back
Top