Dave's Brain

Browse - Programming Tips - How can I quickly convert a hex digit to an int?

Date: 2017apr27
Language: C/C+
Keywords: atoi, hexadecimal

Q.  How can I quickly convert a hex digit to an int?

A.

inline int xtoi(const char c) { if (isdigit(c)) return c - '0'; 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.