Write a C program to convert an integer into a binary
string?
Answer / 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 |
any string of bits of length 'n' represents a unique non- negative integer between.............?
what is difference b/w extern & volatile variable??
Do you have any idea about the use of "auto" keyword?
we compile c program in 32 processor and 64 bit processor .exe file is created in both the processors. if we want to run .exe file in 64 bit processor which is created in 32 bit processor. is that .exe file is run or not if it is not run why?
What is keyword with example?
write a 'c' program to sum the number of integer values
What is the symbol indicated the c-preprocessor?
What is calloc()?
How can you convert integers to binary or hexadecimal?
Stimulate calculator using Switch-case-default statement for two numbers
What header files do I need in order to define the standard library functions I use?
Which function in C can be used to append a string to another string?