def _crc16(data, crc, table):
    """Calculate CRC16 using the given table.
    `data`      - data for calculating CRC, must be bytes
    `crc`       - initial value
    `table`     - table for calculating CRC (list of 256 integers)
    Return calculated value of CRC
    """
    for byte in data:
        crc = crc << 8 & 65280 ^ table[crc >> 8 & 255 ^ byte]
    return crc & 65535
