def twos_complement(input_value, num_bits=8):
    """Calculates the unsigned int which binary matches the two's complement of the input"""
    mask = 2**(num_bits - 1)
    return ((input_value & mask) - (input_value & ~mask)) & ((2 ** num_bits) - 1)