Dave's Brain

Browse - programming tips - fast hex to int

Date: 2010nov25
Language: C/C++
Keywords: fast, speed, integer, hex, hexadecimal

Q.  How can I quickly convert a an ASCII hex number into an integer?

A.

// To convert a 1 digit hexadecimal ASCII number into an integer
inline int xtoi(const char c)
{
	if (isdigit(c))
	{
		return c - '0';
	}
	else
	{
		return tolower(c) - 'a' + 10;
	}
}
What this info useful to you? You can donate to say thanks

Add a comment

Sign in to add a comment
Copyright © 2008-2012, dave - Code samples on Dave's Brain is licensed under the Creative Commons Attribution 2.5 License. However other material, including English text has all rights reserved.
Advertisements: