+ 4

Conversion from binary to decimal

Hey everyone, I’m a bit confused. I was given a task to write a code which would convert binary into decimal (binary fractions as well). The code itself seems running okay, but when I copy it to a compiler on a website, it runs 3 tests correctly and says “runtime error” on the 4 test. I suppose my code is not very efficient and elegant, but for all my tests it was still working without any mistakes within a second. Please share your thoughts about what could be the alternative solution. https://code.sololearn.com/crj6bAc7FpA3/?ref=app

26th Sep 2018, 9:57 AM
Roma
2 Antworten
+ 2
 codescracker.com In Python, you can simply use the bin() function to convert from a decimalvalue to its corresponding binaryvalue. And similarly, the int() function to convert a binary to its decimalvalue. The int() function takes as second argument the base of the number to be converted, which is 2 incase of binary numbers.
26th Sep 2018, 10:10 AM
Mradul Uttam
Mradul Uttam - avatar
+ 1
Mradul Uttam yeah, but the int() function is not working for fractions, or is it?
26th Sep 2018, 11:32 AM
Roma