62,620
社区成员
发帖
与我相关
我的任务
分享
char* g(unsigned int a) {
char k[] = "0123456789ABCDEF";
char r[sizeof (a)*2];
int i = 0;
while (a != 0) {
r[i++] = k[a % 16];
a /= 16;
}
while (i < 4) {
r[i++] = '0';
}
char* t = malloc(i + 1);
int j = 0;
while (j < i) {
t[j++] = r[i - 1 - j];
}
t[i] = 0;
return t;
}
String getCRC(byte[] arg) {
int i, accumulator, data, index;
String returnValue = new String();
accumulator = 0xffff;
for (i=0; i<arg.length; i++) {
data = arg[i];
index = (accumulator >> 8) ^ data;
accumulator = (accumulator << 8) ^ this.crcTable[index];
}
accumulator ^= 0xffff;
returnValue = Integer.toHexString(accumulator).toUpperCase();
for (i=returnValue.length(); i<4; i++)
returnValue = '0' + returnValue;
return returnValue;
}