All pastes #371682 Raw Edit

Unnamed

public text v1 · immutable
#371682 ·published 2007-02-25 15:42 UTC
rendered paste body

#include "stdafx.h"
#include "math.h"


int bindec( int x, int y, int z);  /* Function Prototype for the "binary" to decimal conversion */


int main(void)
{
	int number;
	int total = 0;
	int power = 1;

	printf("Enter a binary number: ");
	scanf("%d", &number);
	
	printf( "%d is %d in decimal.\n", number, bindec( number, total, power));
	
	
	return 0;
}
/* The function bindec */

int bindec(int x, int y, int z)
{
	while(x > 0)
	{
		y+(x%10)*z;
		z = z*2;
		x = x/10;
	}
	return y;
}