We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 95161a0 commit 376cb60Copy full SHA for 376cb60
maths/base_neg2_conversion.py
@@ -1,5 +1,5 @@
1
import doctest
2
-def decimal_to_negative_base_2(n: int) -> int:
+def decimal_to_negative_base_2(num: int) -> int:
3
"""
4
This function returns the number negative base 2
5
of the decimal number of the input data.
@@ -20,15 +20,15 @@ def decimal_to_negative_base_2(n: int) -> int:
20
>>> decimal_to_negative_base_2(7)
21
11011
22
23
- if n == 0:
+ if num == 0:
24
return 0
25
ans = ""
26
- while n != 0:
27
- rem = n % -2
28
- n = n // -2
+ while num != 0:
+ rem = num % -2
+ num = num // -2
29
if rem < 0:
30
rem += 2
31
- n += 1
+ num += 1
32
33
ans = str(rem) + ans
34
0 commit comments