public static byte[] hexStringToByteArray(String str) {
byte[] byteArray = new byte[str.length()/2];
int len = byteArray.length;
int j = 0;
for (int i = 0; i
j = (i<<1);
byteArray[i] = 0;
char c = str.charAt(j);
if ('0'<=c && c<='9') {
byteArray[i] |= ((c-'0')<<4);
} else if ('A'<=c && c<='F') {
byteArray[i] |= ((c-'A'+10)<<4);
} else if ('a'<=c && c<='f') {
byteArray[i] |= ((c-'a'+10)<<4);
} else {
// TODO: Exception
}
j++;
c = str.charAt(j);
if ('0'<=c && c<='9') {
byteArray[i] |= (c-'0');
} else if ('A'<=c && c<='F') {
byteArray[i] |= (c-'A'+10);
} else if ('a'<=c && c<='f') {
byteArray[i] |= (c-'a'+10);
} else {
}
}
return byteArray;
}
2013年9月11日 11:50