def msg_crc16(msg: bytes) -> int:
    """Compute CRC16 of a bytes message."""
    crc = 0xFFFF
    for item in msg:
        next_byte = item
        crc ^= next_byte
        for _ in range(8):
            lsb = crc & 1
            crc >>= 1
            if lsb:
                crc ^= 0xA001
    return crc