Created
January 26, 2014 02:25
-
-
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
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
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