D DigitalBoy New Member Sep 6, 2003 #1 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.
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.
bculver New Member Sep 7, 2003 #2 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!
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!
C Cprogrammer_Rajeev New Member Sep 8, 2003 #3 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
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