Created
February 20, 2015 00:45
-
-
Save ryankurte/58ec694d4700704a8b3e to your computer and use it in GitHub Desktop.
C Hexidecimal to Integer Converter
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
uint8_t hex_to_int(uint8_t c) | |
{ | |
if ((c >= 48) && (c <= 57)) { | |
//Numeric data | |
return (c - 48); | |
} else if ((c >= 65) && (c <= 70)) { | |
//Lower case ASCII | |
return (c - 65 + 10); | |
} else if ((c >= 97) && (c <= 102)) { | |
//Upper case ascii | |
return (c - 97 + 10); | |
} else { | |
//Invalid symbols | |
return 0; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment