| | |
| | | * @param endIndex 截止下标 |
| | | * @return CRC |
| | | */ |
| | | @SuppressWarnings("unused") |
| | | public int CRC16_table(byte[] bs, int startIndex, int endIndex) { |
| | | int x ; |
| | | int crc = 0xffff; |
| | |
| | | } |
| | | return crc ; |
| | | } |
| | | |
| | | /** |
| | | * 16位的CRC值 ,查表法 |
| | | * 16位的CRC值是无符号两字节整数, |
| | | * @param len 数组长度 |
| | | * @param bs 字节数组 |
| | | * @param crc 原始crc值 |
| | | * @return CRC |
| | | */ |
| | | public short CRC16_table(byte[] bs) { |
| | | short x ; |
| | | short crc = (short)0xffff; |
| | | if(bs != null && bs.length > 0){ |
| | | for(byte b : bs){ |
| | | x = (short)(crc ^ b) ; |
| | | crc = (short)((crc >> 8) ^ crc16_rev_table[x & 0x00FF]) ; |
| | | public int CRC16_table(int len, byte[] bs, int crc) { |
| | | int x ; |
| | | if(bs != null){ |
| | | for (int i = 0 ; i < len; i++){ |
| | | x = (crc ^ bs[i]) ; |
| | | crc = ((crc >> 8) ^ crc16_rev_table[x & 0x00FF]) ; |
| | | } |
| | | } |
| | | return crc ; |