Write a C program to convert an integer into a binary
string?

Answer Posted / vadivelt

#include<stdio.h>
char *IntToBinString(int no);
main()
{
int no;
printf("ENTER THE NO: ");
scanf("%d",&no);
printf("\nBINARY O/P STRING:\n%s",IntToBinString(no));
getch();
}
char *IntToBinString(int no)
{
char *ptr;
int i, size;
size = sizeof(int)*8;
ptr = (char *)malloc(sizeof(int)*8);
for(i = size - 1; i >= 0; i--)
{
if(no >> i & 0x01)
{
*ptr++ = 49;
}
else
{
*ptr++ = 48;
}
}
*ptr = '\0';
return (ptr - size);
}

Is This Answer Correct ?    9 Yes 3 No



Post New Answer       View All Answers


Please Help Members By Posting Answers For Below Questions

"C" language developed by "Dennis Ritchie" at AT & T. his remarks are a) too general, too abstract b) could deal with only specific problems c) lost generality of BCPL and B restored d) no remarks

662


Explain goto?

722


why arguments can generally be passed to functions a) sending the values of the arguments b) sending the addresses of the arguments c) a & b d) none of the above

649


Tell me with an example the self-referential structure?

570


What is the difference between class and object in c?

588






Explain what is the purpose of "extern" keyword in a function declaration?

625


where are auto variables stored? What are the characteristics of an auto variable?

597


What is line in c preprocessor?

618


Why is sizeof () an operator and not a function?

593


a construct the"else" part of "if" statement contains anoth "if else" statement is called a) if-else b) else-if-else c) if-else-if-else d) chain if/if-else-if

710


What does stand for?

603


develop algorithms to add polynomials (i) in one variable

1747


Differentiate between static and dynamic modeling.

626


How can you determine the maximum value that a numeric variable can hold?

643


What is the size of enum in bytes?

594