public String getCRC16(byte[] bytes) {
//CRC寄存器全为1
int CRC = 0x0000ffff;
//多项式校验值
int POLYNOMIAL = 0x0000a001;
int i, j;
for (i = 0; i < bytes.length; i++) {
CRC ^= ((int) bytes[i] & 0x000000ff);
for (j = 0; j < 8; j++) {
if ((CRC & 0x00000001) != 0) {
CRC >>= 1;
CRC ^= POLYNOMIAL;
} else {
CRC >>= 1;
}
}
}
//结果转换为16进制
String result = Integer.toHexString(CRC).toUpperCase();
if (result.length() != 4) {
StringBuffer sb = new StringBuffer("0000");
result = sb.replace(4 - result.length(), 4, result).toString();
}
//交换高低位
//return result.substring(2, 4) + result.substring(0, 2);//低前高后
return result;//高位在前,低位在后
}

最新文章

  1. bat脚本参数 if goto choice for使用的学习笔记。
  2. [转]&lt;jsp:include&gt;和&lt;%@include%&gt;的区别
  3. c#解析xml
  4. 【转】Android之自定义Adapter的ListView
  5. P6 EPPM Manual Installation Guide (Oracle Database)
  6. python2.7系列安装失败的办法
  7. safari的input问题
  8. Android屏幕大小适配问题解决
  9. android新浪分享实例
  10. 【转】判断URL是否能够访问
  11. java_web学习(2)Servlet
  12. iOS开发 - Swift使用JavaScriptCore与JS交互
  13. 解决GJson 获取web api数据出现Not a JsonObject问题
  14. ubuntu下zip文件操作
  15. Java自定义类加载器与双亲委派模型
  16. Spring security实现国际化问题
  17. &lt;&lt;梦断代码&gt;&gt;阅读笔记三
  18. MyEclipse上有main函数类运行报错:Editor does not contain a main type
  19. POJ 2607 Fire Station(Floyd打表+枚举更新最优)
  20. 数字签名算法(C#)

热门文章

  1. Laravel5.4 队列简单配置与使用
  2. Leetcode1_两数之和
  3. 吴裕雄--天生自然 HADOOP大数据分布式处理:主机与服务器时间同步设置
  4. 手机遥控Office,变身演讲达人
  5. XiaoXiao
  6. E丢丢App重设计总结
  7. vivado操作基本问题
  8. Python自动化之数据驱动(转载下自己的日常练习笔记)
  9. id0-rsa WP合集
  10. SpringMVC 数据校验(JSR-303)