java crc64_java版crc64 | 学步园
public class crc64 {private static final long INITIALCRC = 0xFFFFFFFFFFFFFFFFL;private static long[] sCrcTable = new long[256];private static final long POLY64REV = 0x95AC9329AC4BC9B5L;static {// http
public class crc64 {
private static final long INITIALCRC = 0xFFFFFFFFFFFFFFFFL;
private static long[] sCrcTable = new long[256];
private static final long POLY64REV = 0x95AC9329AC4BC9B5L;
static {
// http://bioinf.cs.ucl.ac.uk/downloads/crc64/crc64.c
long part;
for (int i = 0; i < 256; i++) {
part = i;
for (int j = 0; j < 8; j++) {
long x = ((int) part & 1) != 0 ? POLY64REV : 0;
part = (part >> 1) ^ x;
}
sCrcTable[i] = part;
}
}
public static final long crc64Long(String in) {
if (in == null || in.length() == 0) {
return 0;
}
return crc64Long(getBytes(in));
}
// 将String转换成字节数组
public static byte[] getBytes(String in) {
byte[] result = new byte[in.length() * 2];// 一个字符占两个字节
int output = 0;
for (char ch : in.toCharArray()) {
result[output++] = (byte) (ch & 0xFF);// 取低8位
result[output++] = (byte) (ch >> 8);// 取高8位
}
return result;
}
// crc64
魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。
更多推荐



所有评论(0)