Binary To Decimal

This algorithm converts binary numbers to decimal numbers.



									/*****Please include following header files*****/
// math.h
/***********************************************/

int BinaryToDecimal(char* bin) {
	int binLength = strlen(bin);
	double dec = 0;

	for (int i = 0; i < binLength; ++i)
	{
		dec += (bin[i] - 48) * pow(2, ((binLength - i) - 1));
	}

	return (int)dec;
}
								


Example

									char* data = "10111101011011010111110";
int value = BinaryToDecimal(data);
								


Output

									6207166