Home » » Convert integer to binary value program in C

Convert integer to binary value program in C

Very easy implementation for convertion a integer value to a binary values. Let us see the program and output. How it performs, i used a string and append output after getting remainder (giving condition on that). Eventually ended up with reverse string which is actual binary value of given number.




#include<stdio.h>
#include<conio.h>
#include<string.h>



void convertToBytes(int a)
{
         int i=0;
        char b[10];
while(a>0)
{
     if(a%2==0)
    {
         b[i]='0';
         i++;
     }
     else
    {
        b[i]='1';
        i++;
     }
 a=a/2;
}

b[i]='\0';
strrev(b);
printf("%s\n",b);

}

void main()
{
   int n;
   printf("Enter Your Number\n");
   scanf("%d",&n);
   convertToBytes(n);
   getch();
}



// Output :



Share this article :

0 comments:

Post a Comment

 
My Other Websites : Ad Networks | Games Copyright © 2014. Study Depth - All Rights Reserved