Skip to content

Instantly share code, notes, and snippets.

@jianminchen
Last active June 26, 2016 17:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jianminchen/2fbf865e2bdb49681bb8c7e9899d5908 to your computer and use it in GitHub Desktop.
Save jianminchen/2fbf865e2bdb49681bb8c7e9899d5908 to your computer and use it in GitHub Desktop.
HexDecimal Char to Integer - a small function
/*
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