Java CRC_16生成函数

来源:互联网 发布:淘宝客服子账号名字 编辑:程序博客网 时间:2024/06/01 18:55

/****************** CRC16*****/ private static int poly = 0x8005; public static short CRC_16(byte[] buf_temp,int len) { int crc_temp=0; int c,i; int index = 0; while ( len != 0 ) { c = buf_temp[index] & 0x000000FF;//extend to int index++; c <<= 8; for(i=0;i<8;i++) { if( ((crc_temp^c)&0x8000) > 0) crc_temp=(crc_temp<<1)^poly; else crc_temp <<= 1; c<<=1; } len--; } return (short) (crc_temp&0xFFFF); } /****************** short to bytes*****/ public static byte lowByte(short value) { return (byte) (value & 0x00FF); } public static byte highByte(short value) { return (byte) ((value >> 8) & 0x00FF); }

原创粉丝点击