最近在作一个接收数据的程序,用到CRC16校验码。在网上搜了一天没有结果,那位高人手里有这个程序希望能给小弟些指点!不胜感激!用java编的。谢谢!!!
解决方案 »
- 怎么在person类实现implements interface abstract
- java编译的一个问题
- 求 struts 2.0 tld 文件,和使用?急,请高手帮帮忙!
- 数据库增删改查 在线等
- 有什么办法让jre在安装之后自动设置系统的环境变量?
- 菜鸟求助:Unknown character set: 'dos' 错误
- 我的程序在内存中制作了html源码(不存在这个文件),可以调用IE打开这个html吗?
- 在不同的DBconnection中,使用preparedstatement会比statement有性能的提高吗?
- 请问高手的问题
- 读XML文件路径碰到的问题。。。。。。。
- 一个入门级的问题,求教
- 线程的问题
* Compilation: javac CRC16.java
* Execution: java CRC16 < data.txt
* Dependencies: StdIn.java
*
* Reads in a sequence of bytes and prints out its 16 bit
* Cylcic Redundancy Check (CRC).
*
* 1 + x + x^5 + x^12 + x^16 is irreducible polynomial.
*
*************************************************************************/public class CRC16 { public static void main(String[] args) {
short crc = (short) 0xFFFF; // initial contents of LFSR while (!StdIn.isEmpty()) {
char c = StdIn.readChar();
for (int i = 0; i < 8; i++) {
boolean c15 = ((crc >> 15 & 1) == 1);
boolean bit = ((c >> (7 - i) & 1) == 1);
crc <<= 1;
if (c15 ^ bit) crc ^= 0x1021; // 0001 0000 0010 0001 (0, 5, 12)
}
}
System.out.println("CRC16 = " + crc);
System.out.println("CRC16 = " + Integer.toHexString(crc));
}}