Conversion from binary to decimal | Sololearn: Learn to code for FREE!
Novo curso! Todo programador deveria aprender IA generativa!
Experimente uma aula grƔtis
+ 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 Respostas
+ 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