def to_bin(self, n):
        """
        2's complement
        32-bit
        :param n:
        :return:
        """
        """
        :param n:
        :return:
        """
        a = abs(n)
        lst = []
        while a>0:
            lst.append(a%2)
            a /= 2

        # 2's complement
        if n>=0:
            lst.extend([0]*(32-len(lst)))
        else:
            pivot = -1
            for i in xrange(len(lst)):
                if pivot==-1 and lst[i]==1:
                    pivot = i
                    continue
                if pivot!=-1:
                    lst[i] ^= 1

            lst.extend([1]*(32-len(lst)))

        return "".join(map(str, reversed(lst)))
dataset/ETHPy150Open algorhythms/LintCode/Convert Integer A to Integer B.py/Solution.to_bin/original