之前是否有人试图进行字幕转换?实际上,我想在下面做一些事情:
public static Object parseZonedDec(byte[] byte_array) throws Exception {
String val = getHexString(byte_array);
int len = val.length();
return val.substring(1, len-1); // not sure if this is correct?
}
public static String getHexString(byte[] b) {
if (b == null) {
return null;
}
StringBuffer sb = new StringBuffer();
for (int i=0; i < b.length; i++)
{
sb.append(Integer.toString( (b[i] & 0xff ) + 0x100, 16).substring(1));
}
return sb.toString().toUpperCase;
}
谢谢!
答案 0 :(得分:0)
您可以尝试下面的代码
public long parseZonedDec(byte[] data) {
long val = 0L;
boolean negative = false;
for (int i = 0; i < data.length; i++) {
int raw = data[i] & UNSIGNED_BYTE;
int digitA = raw >> 4;
int digitB = raw & BITS_RIGHT;
if (digitA < 10) {
val *= 10L;
val += (long) digitA;
} else if (digitA == 11 || digitA == 13) {
negative = true;
}
if (digitB < 10) {
val *= 10L;
val += (long) digitB;
} else if (digitB == 11 || digitB == 13) {
negative = true;
}
}
if (negative)
val = -val;
return val;
}