Golgappa.net | Golgappa.org | BagIndia.net | BodyIndia.Com | CabIndia.net | CarsBikes.net | CarsBikes.org | CashIndia.net | ConsumerIndia.net | CookingIndia.net | DataIndia.net | DealIndia.net | EmailIndia.net | FirstTablet.com | FirstTourist.com | ForsaleIndia.net | IndiaBody.Com | IndiaCab.net | IndiaCash.net | IndiaModel.net | KidForum.net | OfficeIndia.net | PaysIndia.com | RestaurantIndia.net | RestaurantsIndia.net | SaleForum.net | SellForum.net | SoldIndia.com | StarIndia.net | TomatoCab.com | TomatoCabs.com | TownIndia.com
Interested to Buy Any Domain ? << Click Here >> for more details...

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

What are header files why are they important?

1044


Explain zero based addressing.

966


What are the rules for identifiers in c?

1029


What is hungarian notation? Is it worthwhile?

1167


What are the two types of functions in c?

943


Tell me can the size of an array be declared at runtime?

987


Why can’t we compare structures?

1226


How can I get the current date or time of day in a c program?

1166


Difference between Shallow copy and Deep copy?

1969


What is "Hungarian Notation"?

1033


What is atoi and atof in c?

1028


What standard functions are available to manipulate strings?

1075


Who is the founder of c language?

1108


Which one to choose from 'initialization lists' or 'assignment', for the use in the constructor?

1019


Write a program in c to replace any vowel in a string with z?

1075