/* numconv.c - convert numbers from hex, octal, binary, decimal */
/* strings into an int */

#include <ctype.h>

int hex2i(char *hexstr)
{
	int loop;
	int total = 0;

	for(loop = 2; loop<strlen(hexstr); loop++)
	{
		total *= 16;

		if(isdigit(hexstr[loop]))
			total += hexstr[loop] - '0';
		else
			total += tolower(hexstr[loop]) - 'a' + 10;
	}

	return total;
}

int bin2i(char *binstr)
{
	int loop;
	int total = 0;

	for(loop = 2; loop<strlen(binstr); loop++)
	{
		total *= 2;
		total += binstr[loop] - '0';
	}

	return total;
}

int oct2i(char *octstr)
{
	int loop;
	int total = 0;

	for(loop = 1; loop<strlen(octstr); loop++)
	{
		total *= 8;
		total += octstr[loop] - '0';
	}

	return total;
}

int dec2i(char *decstr)
{
	int loop;
	int total = 0;

	for(loop = 0; loop<strlen(decstr); loop++)
	{
		total *= 10;
		total += decstr[loop] - '0';
	}

	return total;
}

/* ... The End ... */

