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?



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

Post New Answer

More C Interview Questions

What is an auto keyword in c?

0 Answers  


main() { printf("\n %d %d %d",sizeof('3'),sizeof("3"),sizeof(3)); }

6 Answers  


Can we initialize extern variable in c?

0 Answers  


Write a code to reverse string seperated by spaces i/p str=India is my country o/p str=aidnI si ym yrtnuoc After writing code, optimize the code

1 Answers  


how to do in place reversal of a linked list(singly or doubly)?

3 Answers  


Explain how to reverse singly link list.

0 Answers  


A collection of functions,calls,subroutines or other data a) library b) header files c) set of files d) textfiles

0 Answers  


What is the relation between # and include<stdio.h>

5 Answers   HCL,


Dear Sir, we are required the bubble sorting programs Regs Prem

1 Answers  


can we have joblib in a proc ?

0 Answers  


main() { int a=4,b=2; a=b<<a + b>>2; printf("%d", a); }

4 Answers   CTS,


who will call your main function in c under linux?

2 Answers  


Categories