ArtsAutosBooksBusinessEducationEntertainmentFamilyFashionFoodGamesGenderHealthHolidaysHomeHubPagesPersonal FinancePetsPoliticsReligionSportsTechnologyTravel
  • »
  • Technology»
  • Computers & Software»
  • Computer Science & Programming

C Program Source Code For Decimal to binary conversion

Updated on January 3, 2013

Following is the C Program to convert any integer from decimal number system to binary number system. Decimal number system is also known by base 10 number as its base is equal to 10 while the binary number system has its base 2.

The integer we have assumed here is if 32 bit so we are right shifting the entered no. 32 times bit by bit and then the ANDing operation will be done bitwise with "1" , if it comes out to be "1" , then the bit is 1 otherwise 0 (zero).

#include <stdio.h>
int main()
{
  int a,j,m;
  printf("Enter an integer in decimal number system you want to convert in binary\n");
  scanf("%d",&a); 
  printf("%d in binary number system is:\n",a);
  for(j= 31;j>=0;j--)
  {
    m=a>>j;
    if(m&1)
      printf("1");
    else
      printf("0");
  } 
  printf("\a"); 
  return 0;
}


Copy the above source code in notepad and save it with extension *.c or as techniche.c . Then compile and run the program .

Lets Vote :)

Do you find C Programming Easy ?

See results

Comments

    0 of 8192 characters used
    Post Comment

    No comments yet.