Last active
June 26, 2016 17:20
-
-
Save jianminchen/2fbf865e2bdb49681bb8c7e9899d5908 to your computer and use it in GitHub Desktop.
HexDecimal Char to Integer - a small function
This file contains 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
/* | |
Get an integer value from HexDecimal char | |
For example, 'F', return value is 15 | |
'9', return value is 9 | |
*/ | |
public static int getInt(char c) | |
{ | |
int number = c - '0'; | |
if (number >= 0 && number <= 9) | |
return number; | |
else | |
{ | |
string charStr = "ABCDEF"; | |
char[] charArr = charStr.ToCharArray(); | |
int value = Array.IndexOf(charArr, c); | |
return 10 + value; | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment