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 any base (e.g., 2, 8, 16, 60) You may not use libraries or built-in functions (e.g., Double.toHexString(...) in Java or ”{0:b}”.format(...)in Python)

please in python exampe 0.5 convert to 0.1

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

OUTPUT :

CODE :

num = int(input('Enter a real number: '))
b = int(input('Enter the base: '))
ans = ''
n = num
#COnvert while n>0
while n>0:
#Find remainder
rem = n%b
#Append it to ans
ans = '('+str(rem)+')'+ans
#Reduce number by b
n = n//b
print(num,'in base',b,' is',ans)

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
  • 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

  • Write a program in C++ that reads a string consisting of a positive integer or a...

    Write a program in C++ that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, the program must use a stack to convert the decimal number to the numeric format. DO NOT USE STACK LIBRARY OR STACK FUNCTIONS OR A STRING LIBRARY. For this assignment you have to use STACK with all methods to convert the decimal number to numeric...

  • JAVA PLEASE 4. Write a recursive program that converts a Hex base value to its decimal...

    JAVA PLEASE 4. Write a recursive program that converts a Hex base value to its decimal equivalent. This program must validate the ueser’s input. You program must have the main method, inputValidate method and hexToDecimal method. Must implement the last method recursively. Here is a sample output. Enter a valid hex number: 10 Your number in decimal is: 16 Do you have another number: yes Enter a valid hex number: 123 Your number in decimal is: 291 Do you have...

  • need help with writing a program that converts i.e. binary to decimal or decimal to hexadecimal...

    need help with writing a program that converts i.e. binary to decimal or decimal to hexadecimal but cannot use the conversion tool built-in Java and please use the switch and write comments to understand.

  • A) Write a function that receives an integer decimal number and converts it to its Hexadecimal...

    A) Write a function that receives an integer decimal number and converts it to its Hexadecimal equivalent B) Write a function that converts a binary number to its corresponding Decimal equivalent BOTH A AND B IN ARDUINO C LANGUAGE

  • Need this in java please Write a program that converts between decimal, hex, and binary numbers,...

    Need this in java please Write a program that converts between decimal, hex, and binary numbers, as shown in Figure. When you enter a decimal value in the decimalvalue text field and press the Enter key, its corresponding hex and binary numbers are displayed in the other two text fields. Likewise, you can enter values in the other fields and convert them accordingly. (c) The program converts between decimal, hex, and binary numbers.

  • c++ the program must use a stack to convert the decimal number to the numeric format....

    c++ the program must use a stack to convert the decimal number to the numeric format. Write a program that reads a string consisting of a positive integer or a positive decimal number and converts the number to the numeric format. If the string consists of a decimal number, Expert Answer

  • C++ Write a program that converts anumber entered in Roman numerals to decimal.

    In C++ Write a program that converts a number entered in Roman numerals to decimal. Your program should consist of a class, say,romanType. An object of typeromanTypeshould do the following:a. Store the number as a Romannumeral.b. Convert and store the number into decimalform.c. Print the number as a Roman numeral ordecimal number as requested by the user.The decimal values of the Roman numerals are:M 1000D 500C 100L 50X 10V 5I 1d. Test your program using the followingRoman numerals: MCXIV, CCCLIX,...

  • Write a program that performs the following tasks: Display a friendly greeting to the user Prompt...

    Write a program that performs the following tasks: Display a friendly greeting to the user Prompt the user for the value to convert (a String) Accept that String Prompt the user for the value of the initial base (an integer) Accept that integer Prompt the user for the desired base of the output (an integer) Accept that integer If the String is not a legal expression of a number in the initial base, display an error message and exit the...

  • write a java program that converts a floating point number to the simple model of the...

    write a java program that converts a floating point number to the simple model of the floating point The simple model uses 1 bit for sign, 5 bits for exponents and 8 bits for significand

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