Question

Using Python In the decimal system (base 10), a natural number is represented as a sequence...

Using Python

In the decimal system (base 10), a natural number is represented as a sequence dndn?1 . . . d0 of (decimal) digits, each of which is in the range 0..9. The value of the number is d0 ×100 +d1 ×101 +···+ dn ×10n. Similarly, in the binary system (base 2), a natural number is represented as a sequence bnbn?1 · · · b0 of (binary) digits, each of which is 0 or 1. The value of the number is b0 ×20 +b1 ×21 +···+bn ×2n. For example, the value of the number whose binary representation is 101is: 1×20+0×21+1×22 =1+0+4=5.

Without using any built-in functions for converting numbers, write a function that takes as input the decimal representation of a positive integer n and returns its binary representation.

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

#####Function starts here

def convertToBinary(decimal):

    while decimal > 0:

        value = int(decimal % 2)

        decimal = int(decimal / 2)

        nbin.append(value)

    nbin.reverse()

    return nbin

# since the Binary value may be too large for certain numbers so I used Char array to store the Binary value

#####Function ends here

#####Driver program

dec = int(input("Enter Decimal Number : "))

nbin=[]

nbin = convertToBinary(dec)

print("Binary value is ", end=": ")

for x in nbin:

    print(x, end='')

Output:

Add a comment
Know the answer?
Add Answer to:
Using Python In the decimal system (base 10), a natural number is represented as a sequence...
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
  • 3.) will use b = 5 c = 25. Recall, a number expressed in base b...

    3.) will use b = 5 c = 25. Recall, a number expressed in base b is a sequence of digits e.g. d3 d2 d1 d0 where each of the digits is between 0 and b-1. The value of d3 d2 d1 d0 would be d3 × b3 + d2 × b2 +d1 × b1 +d0 × b0 . In the case where b is bigger than 10, some of the digits will be letters. For example, if b is...

  • Given the following representation of a base 10 decimal number below for n: In this system,...

    Given the following representation of a base 10 decimal number below for n: In this system, a number is represented as: Sk-1... S2 S, So S-15-2... S- and has the value of: Integral part Sk-1+ ... +S,+ So Fractional part S_1+5-2 + ... +5_1 n+ Explain a general formula for the smallest positive value for n [base 10 decimal number]

  • In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of num...

    In the base conversion problem, the task to be performed is to convert the number of base n to decimal. The base of number can be anything such that all digits are represented using 0 to 9 and A to Z. Value of A is 10, Value for B is 11 and so on. So, write a program to convert a number to decimal Example: Input number is given as string and the output is an integer. Input Output Input...

  • please include only the digits of the appropriate number system. In particular, do not precede the...

    please include only the digits of the appropriate number system. In particular, do not precede the answers with ‘0x’ or ‘0b’ or follow your answers with base indicators, like subscript 2 or 10. 1. A processor uses 24 bits for its memory addressing. How many possible distinct locations (in decimal) can the computer address? The computer memory address locations are numbered from 0 to the maximum. If a memory locations' address is (7243)10, how is this address represented in binary...

  • 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

  • C++ Convert a Number from Binary to Decimal using a stack: The language of a computer...

    C++ Convert a Number from Binary to Decimal using a stack: The language of a computer is a sequence of Os and 1s. The numbering system we use is called the decimal system, or base 10 system. The numbering system that the computer uses is called the binary system, or base 2 system. The purpose of this exercise is to write a function to convert a string representing a binary number from base 2 to base 10. To convert a...

  • Using positional notation, express the number 517 in Base 8 Note: Start your expression with an-s...

    Using positional notation, express the number 517 in Base 8 Note: Start your expression with an-sign. Use symbols+and for your operators. Do not include resulting value Question 47 (1 point) Saved Given a fixed-sized number scheme where 2 is the number of digits used for the 10's complement representation how many positive integers can be represented? Using positional notation, express the number 517 in Base 8 Note: Start your expression with an-sign. Use symbols+and for your operators. Do not include...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not receive any credit, so be sure that your code interprets correctly...

  • NOTE: Write the Program in python as mentioned below and use while loop and flags as...

    NOTE: Write the Program in python as mentioned below and use while loop and flags as necessary. And please write the code following the program description given below. DON'T use Function concept or any other concept except while loop,if-else. Directions: Read the program description below carefully. All requirements must be met by your program to receive full credit. Thus, pay particular attention to input and output requirements, structural requirements, and so on. Furthermore, code that contains syntax errors will not...

  • (3 pts) Consider an unsigned fixed point decimal (Base10) representation with 8 digits, 5 to the...

    (3 pts) Consider an unsigned fixed point decimal (Base10) representation with 8 digits, 5 to the left of the decimal point and 3 to the right. a.      What is the range of the expressible numbers?    b.      What is the precision?    c.       What is the error?    ______________________________________________________________________________   (3 pts) Convert this unsigned base 2 number, 1001 10112, to each base given below   (Note: the space in the binary string is purely for visual convenience) Show your work. Using...

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