`
lingfenfei
  • 浏览: 1590 次
  • 性别: Icon_minigender_1
  • 来自: 福建
文章分类
社区版块
存档分类
最新评论

JAVA CRC16 字符器校验. 污染源在线自动监控(监测)系统

 
阅读更多

package com.fg.water;

public class CRCTest {

/**
* @param args
*/
public static void main(String[] args) {
String temp = "ST=32;CN=2011;PW=122333;MN=88888880000005;CP=&&DataTime=20120416225856;060-Rtd=0.06,060-Flag=N;011-Rtd=0.00,011-Flag=N;001-Rtd=7.64,001-Flag=N&&";
// ##0077QN=20120416225111069;ST=91;CN=9021;PW=122333;MN=88888880000006;Flag=1;CP=&&&&4100
// ##0144ST=32;CN=2011;PW=122333;MN=88888880000005;CP=&&DataTime=20120416225856;060-Rtd=0.06,060-Flag=N;011-Rtd=0.00,011-Flag=N;001-Rtd=7.64,001-Flag=N&&3AC0
Integer[] regs = new Integer[temp.length()];
for (int i = 0; i < temp.length(); i++) {
regs[i] = (int) temp.charAt(i);
}
int por = 0xFFFF;
for (int j = 0; j < regs.length; j++) {
por = por >> 8;
por ^= regs[j];
for (int i = 0; i < 8; i++) {
if ((por & 0x01) == 1) {
por = por >> 1;
por = por ^ 0xa001;
} else
por = por >> 1;
}
}
System.out.println(Integer.toHexString(por));
}
}

分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics