def calc_crc16(binary_data, crc=65535):
    """
    Calculates CRC16 on binary_data

    :param int crc: CRC value to start calculation with
    :param bytearray binary_data: Array with data to run CRC16 calculation on
    :return int: Calculated CRC value of binary_data
    """
    if not isinstance(binary_data, bytes):
        raise RuntimeError('calc_crc16 requires bytes input')
    for b in binary_data:
        crc = crc >> 8 & 255 | crc << 8 & 65280
        crc ^= b
        crc ^= (crc & 255) >> 4
        crc ^= crc << 8 << 4
        crc ^= (crc & 255) << 4 << 1
    return crc & 65535
