Question

Write a program that receives a real number in decimal (base 10) and converts it into...

Write a program that receives a real number in decimal (base 10) and converts it into binary (base 2).•You may not use libraries or built-in functions (e.g., Double.toHexString(...) in Java or ”{0:b}”.format(...)in Python)

please in python and example 0.5 convert to 0.1

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Python 3 code

============================================================================================


def FractiontoBinary(number):

if(number >= 1 or number <= 0):
return "Input is not in real number"
  
  
output = "."
  
while(number > 0):
  
# Multiply number by two
temp = number * 2
if (temp>= 1):
output = output + "1"
number = temp - 1
  
else:
output = output + "0"
number = temp
  
return output
  
num=float(input('Enter real number in base 10: '))
ans = FractiontoBinary(num)
print(num,' ->',ans)
  
  

============================================================================================

Output

Add a comment
Know the answer?
Add Answer to:
Write a program that receives a real number in decimal (base 10) and converts it into...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT