A pure C function that will do the hex-2-int conversion.
This function takes only a single char.
/** Convert a hex char to an int.
@param c Single character representing a hexadecimal char.
@return Returns the integer value.
*/
int hex(char c) {
if ('0' <= c && c <= '9') return c - '0';
if ('a' <= c && c <= 'f') return c - 'a' + 10;
if ('A' <= c && c <= 'F') return c - 'A' + 10;
return -1;
}
Download the ready-for-use source file (.m) of Hex to int conversion (single char)
No comments:
Post a Comment