/*
**	Copyright (c) Leigh Brasington 2012.  All rights reserved.
**	This code may be used and reproduced without written permission.
**
**	 C/C++ function to convert an ANSI hexadecimal string to an int
**
**	Keywords: Convert hexadecimal string int C/C++
*/

int
xtoi(char *hexstring)
{
	int	i = 0;
	
	if ((*hexstring == '0') && (*(hexstring+1) == 'x'))
		  hexstring += 2;
	while (*hexstring)
	{
		char c = toupper(*hexstring++);
		if ((c < '0') || (c > 'F') || ((c > '9') && (c < 'A')))
			break;
		c -= '0';
		if (c > 9)
			c -= 7;
		i = (i << 4) + c;
	}
	return i;
}


Leigh Brasington's Freeware
Back to Leigh's Home Page Site Map                   Site Search 


Permalink http://leighb.com/xtoi.htm [] Hosted by
Leigh Brasington / / Revised 24 Mar 12