this function returns the number negative base 2 of the decimal number of the input data args int the decimal number to convert returns int the negative base 2 number examples decimaltonegativebase20 0 decimaltonegativebase219 111101 decimaltonegativebase24 100 decimaltonegativebase27 11011 this function returns the number negative base 2 of the decimal number of the input data args int the decimal number to convert returns int the negative base 2 number examples decimal_to_negative_base_2 0 0 decimal_to_negative_base_2 19 111101 decimal_to_negative_base_2 4 100 decimal_to_negative_base_2 7 11011
def decimal_to_negative_base_2(num: int) -> int:
    
    if num == 0:
        return 0
    ans = ""
    while num != 0:
        num, rem = divmod(num, -2)
        if rem < 0:
            rem += 2
            num += 1
        ans = str(rem) + ans
    return int(ans)


if __name__ == "__main__":
    import doctest

    doctest.testmod()