0
I cant seem to wrap my head around why this code works. When i try to read through the code i cant get the same answer. Help pls
2 Antworten
+ 3
Ex : 5
=> 5%2 + 10 * convert(5//2) #next call with 2
1 + 10*( 2%2 + 10*(convert(2//2)) ) # 1
1 + 10*( 0 + 10*(1%2+ 10*(convert(1//2))) ) #0
=> 1 + 10*( 0 + 10*(1 + 10*0) )
1+ 10*( 0 + 10*(1))
1 + 10*(10)
= 101
hope it helps..
+ 1
Hi! You have to understand recursion to understand how it works. But you can do the calculation with pen an paper to understand the math behind.
It’s also important to understand the result is an integer here. Often binary numbers is represented by a string.