result
to store the binary representation.n
is 0, return '0' as the binary representation.n
is not equal to 0:
a. Calculate the remainder of n
divided by -2.
b. If the remainder is negative, add 2 to the remainder and increment n
by 1.
c. Divide n
by -2.
d. Append the remainder to the result
string.result
string to get the correct binary representation.result
string.