from typing import Tuple


def _convert_twos_complement(obj: int) -> Tuple[int, str]:
    """ Converts a negative integer to a twos complement binary string to the nearest octet
    Args:
        obj: Negative integer

    Returns:
        The required length in octets of the binary two's complement representation and
        a string of octal length of the two's complement representation of the integer

    """
    if obj < -32768:
        raise OverflowError('[PyASN1PEREncoder][ERROR]: Value too small to encode, hard limit '
                            'set in per_encoder.py')

    x = 0
    for x in range(7, 32, 8):
        if -1*obj < pow(2, x):
            break
    total_remainder = pow(2, x) + obj
    bin_str = ''
    for y in range(x, -1, -1):
        if pow(2, y) <= total_remainder:
            bin_str += '1'
            total_remainder -= pow(2, y)
        else:
            bin_str += '0'
    bin_str = '1' + bin_str[1:]
    return int((x + 1)/8), bin_str