C program to convert the given binary number into its equivalent decimal

by Nideesh C on April 12, 2011 · 0 comments

in C Programming




/* C program to convert the given binary number into its equivalent decimal */

#include <stdio.h>

void main()
{
  int   num, bnum, dec = 0, base = 1, rem ;

  printf("Enter the binary number(1s and 0s)\n");
  scanf("%d", &num);           /*Enter maximum five digits or use long int*/

  bnum = num;

  while( num > 0)
  {
    	rem = num % 10;
	 dec = dec + rem * base;
	 num = num / 10 ;
    	base = base * 2;
  }

  printf("The Binary number is = %d\n", bnum);
  printf("Its decimal equivalent is =%d\n", dec);

} 			/* End of main() */

/*---------------------------------------------------
Outpput
Enter the binary number(1s and 0s)
1010
The Binary number is = 1010
Its decimal equivalent is =10
----------------------------------------------------*/



Not Satisfied ? Just search & get the result

Related Posts Plugin for WordPress, Blogger...
Be Sociable, Share!

Related posts:

  1. C program to convert the given binary number into its equivalent decimal
  2. C program to convert the given binary number into decimal
  3. C program to accept a decimal number and conert it binary and count the number of 1′s in the binary number
  4. Sample – Program to convert 2-digit octal number into binary number and print it.
  5. C program to check whether a given number is prime or not and output the given number with suitable message

Leave a Comment

Previous post:

Next post: