Skip to content

Instantly share code, notes, and snippets.

@SIRHAMY
Created January 26, 2014 02:25
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 SIRHAMY/8627320 to your computer and use it in GitHub Desktop.
Save SIRHAMY/8627320 to your computer and use it in GitHub Desktop.
Converts a string of hexadecimal ASCII characters to the int primitive data type
public static int strxtoi(String hex)
{
int result = 0;
for(int i = 0; i<hex.length();i++)
{
int scalar = 0;
if(hex.charAt(i)>57)
{
scalar = hex.charAt(i) - 55;
}
else
{
scalar = hex.charAt(i) - 48;
}
for(int j = i+1; j<hex.length(); j++)
{
scalar*=16;
}
result+=scalar;
}
return result;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment