daily log 10.05.20

less than 1 minute read

Binary to Num:

my_sum = 0
for i, num in enumerate(test[::-1]):
    if int(num) != 0:
        my_sum += (2**i)
my_sum

Submission:

def bitwiseComplement(N):
    """
    :type N: int
    :rtype: int
    """

    def getComplimentFromNum(num):
        before = bin(num)[2:]
        compliment = ['0' if n == '1' else '1' for n in before]
        print(compliment)
        return compliment

    def getNumFromCompliment(compliment):
        joined = ''.join(compliment)
        print(joined)
        return int(joined,2)


    step1 = getComplimentFromNum(N)
    step2 = getNumFromCompliment(step1)

    return step2