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

main() { printf("hello"); fork(); }

1180


Is it better to use a macro or a function?

1146


If null and 0 are equivalent as null pointer constants, which should I use?

1191


Write a program to identify if a given binary tree is balanced or not.

1136


What is the purpose of void in c?

1055


What are lookup tables in c?

986


Explain goto?

1136


Which is not valid in C a) class aClass{public:int x;}; b) /* A comment */ c) char x=12;

1054


What are predefined functions in c?

1072


Why doesnt long int work?

1019


Do you know the purpose of 'register' keyword?

1011


What is structure in c explain with example?

1147


What is a list in c?

1017


When should you not use a type cast?

1107


What is the use of c language in real life?

1005