0

can someone explain how this code work. About recursion

https://code.sololearn.com/cR6C70vn5X5d/?ref=app I dont understand why the num return is reverse.then can somebody explain the math logic that going on in code pls 🙏🙏.thank youu....

23rd Jun 2023, 8:21 AM
Aisy Danish Mohd Nazry
Aisy Danish Mohd Nazry - avatar
3 ответов
+ 2
The code recursively converts a decimal number to its binary representation by repeatedly dividing the number by 2 and appending the least significant bit at each step.
23rd Jun 2023, 2:39 PM
Souhail Ben Belhassen
Souhail Ben Belhassen - avatar
+ 2
This will not return reverse. This is code to convert a decimal number into a binary number. See for example : Input 5: then it will return 101 If input is 7 then it will return 111 , the binary equaling number. 5 => 5%2 + 10* ( convert(5//2)) 1 + 10* ( 2%2 + 10*(convert(2//2)) 1+10*( 0+10*( 1%2 + 10*(convert(1//2))) 1+ (10*(0+10*(1+10*convert(0))) 1+ (10*(0+10)) = 101
23rd Jun 2023, 2:57 PM
Jayakrishna 🇮🇳
0
The code calculates the binary number of the input and displays all the binaries that are present in the final binary number. For example if input is 128 then the output is 128 64 32 16 8 4 2 1 0 10000000 The "10000000" is the final binary number of your given input.
26th Jun 2023, 9:56 AM
Danish Zubair
Danish Zubair - avatar