标签:android
private static byte hexValueOf(String hex) { byte result = 0; if (hex.charAt(0) == '0' && (hex.charAt(1) == 'X' || hex.charAt(1) == 'x')) { for (int i = 2; i < hex.length(); i++) { char temp = hex.charAt(i); if (i == 2) { if (temp == '0' || temp == '1' || temp == '2' || temp == '3' || temp == '4' || temp == '5' || temp == '6' || temp == '7') { result += Byte.valueOf(temp + "") * 16; } } else { if (temp == '0' || temp == '1' || temp == '2' || temp == '3' || temp == '4' || temp == '5' || temp == '6' || temp == '7') { result += Byte.valueOf(temp + ""); } if (temp == 'A' || temp == 'a' || temp == 'B' || temp == 'b' || temp == 'C' || temp == 'c' || temp == 'D' || temp == 'd' || temp == 'E' || temp == 'e' || temp == 'F' || temp == 'f') { switch (temp) { case 'A': result += Byte.valueOf(10 + ""); break; case 'a': result += Byte.valueOf(10 + ""); break; case 'B': result += Byte.valueOf(11 + ""); break; case 'b': result += Byte.valueOf(11 + ""); break; case 'C': result += Byte.valueOf(12 + ""); break; case 'c': result += Byte.valueOf(12 + ""); break; case 'D': result += Byte.valueOf(13 + ""); break; case 'd': result += Byte.valueOf(13 + ""); break; case 'E': result += Byte.valueOf(14 + ""); break; case 'e': result += Byte.valueOf(14 + ""); break; case 'F': result += Byte.valueOf(15 + ""); break; case 'f': result += Byte.valueOf(15 + ""); break; default: break; } } } } } return result; }
System.out.println("<<<<<"+(hexValueOf("0X7f"))); System.out.println("<<<<<"+(hexValueOf("0X7f")==127));
标签:android
原文地址:http://blog.csdn.net/u014600432/article/details/42150695