Dave's Brain

Browse - Programming Tips - How can I quickly convert a an ASCII hex number into an integer?

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; } }

Add a comment

Sign in to add a comment
Copyright © 2008-2017, 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.