def parity_check(data):
    # 计算数据中 1 的个数
    # 将16进制转10进制int then to 2进制str
    count = bin(int(data, 16))[2:].count('1')

    # 根据 1 的个数确定奇偶位
    parity = '0' if count % 2 == 0 else '1'

    return parity


# 示例数据
data = '10110101'

# 进行奇偶校验
parity = parity_check(data)

# 输出奇偶位
print("奇偶位:", parity)


def to_bin(x, length=0):
    binary_str = bin(x)[2:]
    return binary_str.zfill(length)


def print_xor(a, b):
    max_length = max(len(to_bin(a)), len(to_bin(b)))
    print(to_bin(a, max_length), to_bin(b, max_length))
    result = a ^ b
    print(to_bin(result, max_length))


print_xor(5, 3)