def signed_to_twos_comp(val: int, n_bits: int) -> int:
    """
    Convert a signed integer to its "two's complement" representation.

    Args:
        val: signed integer
        n_bits: number of bits (which must reflect a whole number of bytes)

    Returns:
        unsigned integer: two's complement version

    """
    assert n_bits % 8 == 0, "Must specify a whole number of bytes"
    n_bytes = n_bits // 8
    b = val.to_bytes(n_bytes, byteorder=sys.byteorder, signed=True)
    return int.from_bytes(b, byteorder=sys.byteorder, signed=False)
Convert a signed integer to its "two's complement" representation.

    Args:
        val: signed integer
        n_bits: number of bits (which must reflect a whole number of bytes)

    Returns:
        unsigned integer: two's complement version