def calculate_parity(bit_string):
    """ Calculates the parity of a bit string
    
    Parameters
    ----------
    bit_string : str
        bit string on which parity is to be calculated
    
    Returns
    -------
    parity :int
        0 if even parity
        1 if odd parity
    """

    parity = 0
    for i in range(len(bit_string)):
        bit = bit_string[i]
        if bit == '1':
            #parity has changed
            if parity == 0:
                parity = 1
            elif parity == 1:
                parity = 0
            else:
                raise Exception("Unexpected error calculating parity")
    return(parity)