java实现:
//序列号压缩算法
private byte[] snCompress (String s){
s = s.toUpperCase(Locale.getDefault());
int len = s.length() / 2;
int ii = 0;
byte[] bs = new byte[len];
for(int i = 0; i < len; ++i) {
char c = s.charAt(ii++);
int h;
if(c > 57) {
h = c - 55;
} else {
h = c - 48;
}
h <<= 4;
c = s.charAt(ii++);
if(c > 57) {
h |= c - 55;
} else {
h |= c - 48;
}
bs[i] = (byte)h;
}
return bs;
}
private byte[] snCompress (String s){
s = s.toUpperCase(Locale.getDefault());
int len = s.length() / 2;
int ii = 0;
byte[] bs = new byte[len];
for(int i = 0; i < len; ++i) {
char c = s.charAt(ii++);
int h;
if(c > 57) {
h = c - 55;
} else {
h = c - 48;
}
h <<= 4;
c = s.charAt(ii++);
if(c > 57) {
h |= c - 55;
} else {
h |= c - 48;
}
bs[i] = (byte)h;
}
return bs;
}