DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Snippets has posted 5883 posts at DZone. View Full User Profile

Binary To Decimal In C

03.24.2012
| 3283 views |
  • submit to reddit
        program to convert binary number to decimal 

#include <stdio.h>
#include <math.h>
main()
{
	int bin,rem,n=0,sum=0;
	printf("please enter binary number");
	scanf("%d",&bin);
	while(bin)
	{
		rem=bin%10;
		sum=sum+(rem*pow(2,n));
		bin=bin/10;
		n++;
	}
	printf("%d\n",sum);	
}
/*
by joseph dias 
email josephdias92@gmail.com
*/