package com.pjmike.netty.server; /** * @Description TODO * @Date 2019/10/14 18:09 * @Author zsj */ public class CRC16MUtil { /** * 计算CRC16校验码 * * @param bytes 字节数组 * @return {@link String} 校验码 * @since 1.0 */ public static byte[] getCRC(byte[] bytes) { 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; } } } // 低字节在前,高字节在后 CRC = ((CRC & 0x0000FF00) >> 8) | ((CRC & 0x000000FF) << 8); String crcStr = Integer.
crc16 modbus校验
最新推荐文章于 2024-01-15 15:54:44 发布