public static void main(String[] args) {
System.out.println(getDecimalNum("85abf"));
}
public static long getDecimalNum(String hexStr) {
int len = hexStr.length();
long sum = 0;
for (int i = 0; i < len; i++) {
char c = hexStr.charAt(len - 1 - i);
int n = Character.digit(c, 16);
sum += n * (1 << (4 * i));
}
return sum;
}
网友评论