+ 1

Can someone explain to me why it returns them in binaries?

def convert(num): if num == 0: return 0 else: return (num % 2 + 10 * convert(num // 2)) a = int(input()) print(convert(a))

16th Aug 2022, 6:12 PM
Josué Varela
Josué Varela - avatar
2 Respuestas
+ 1
Recursive base transformation is not a easy topic, you better try to calculate it by hand and write it down on a paper. Lastly, the result is only resemble a binary by an integer, not a true binary.
16th Aug 2022, 6:39 PM
abpatrick catkilltsoi
abpatrick catkilltsoi - avatar
+ 1
This is code for converting a integer to binary equalent. ex: 2 => 0 + 10*( 1+10*(0) ) = 10 3 => 1 + 10*( 1+10*(0) ) = 11
16th Aug 2022, 6:26 PM
Jayakrishna 🇮🇳