1answer.
Ask question
Login Signup
Ask question
All categories
  • English
  • Mathematics
  • Social Studies
  • Business
  • History
  • Health
  • Geography
  • Biology
  • Physics
  • Chemistry
  • Computers and Technology
  • Arts
  • World Languages
  • Spanish
  • French
  • German
  • Advanced Placement (AP)
  • SAT
  • Medicine
  • Law
  • Engineering
Damm [24]
2 years ago
5

6.23 LAB: Convert to binary - functions Instructor note: This is a lab from a previous chapter that now requires the use of a fu

nction. If you weren't able to solve it before, think of this as a new opportunity. Write a program that takes in a positive integer as input, and outputs a string of 1's and 0's representing the integer in binary. For an integer x, the algorithm is: As long as x is greater than 0 Output x % 2 (remainder is either 0 or 1) x = x // 2 Note: The above algorithm outputs the 0's and 1's in reverse order. You will need to write a second function to reverse the string. Ex: If the input is: 6 the output is: 110 Your program must define and call the following two functions. The function integer_to_reverse_binary() should return a string of 1's and 0's representing the integer in binary (in reverse). The function reverse_string() should return a string representing the input string in reverse. def integer_to_reverse_binary(integer_value) def reverse_string(input_string)
Computers and Technology
1 answer:
Kitty [74]2 years ago
3 0

Answer:

The program in Python is as follows:

import math

def integer_to_reverse_binary(integer_value):

   remainder = ""

   while integer_value>=1:

       remainder+=str(integer_value % 2)

       integer_value=math.floor(integer_value/2)

   reverse_string(remainder)

def reverse_string(input_string):

   binaryOutput=""

   for i in range(len(input_string)-1,-1,-1):

       binaryOutput = binaryOutput + input_string[i]

   print(binaryOutput)

integer_value = int(input("Enter a Number : "))

integer_to_reverse_binary(integer_value)

Explanation:

This imports the math module

import math

This defines the integer_to_reverse_binary function

def integer_to_reverse_binary(integer_value):

This initializes the remainder to an empty string

   remainder = ""

This loop is repeated while the integer input is greater than or equal to 1

   while integer_value>=1:

This calculates the remainder after the integer value is divided by 2

       remainder+=str(integer_value % 2)

This gets the floor division of the integer input by 2

       integer_value=math.floor(integer_value/2)

This passes the remainder to the reverse_string function

   reverse_string(remainder)

The reverse_string function begins here

def reverse_string(input_string):

This initializes the binaryOutput to an empty string

   binaryOutput=""

This iterates through the input string i.e. the string of the remainders

   for i in range(len(input_string)-1,-1,-1):

This reverses the input string

       binaryOutput = binaryOutput + input_string[i]

This prints the binary output

   print(binaryOutput)

<u>The main begins here</u>

This gets input for integer_value

integer_value = int(input("Enter a Number : "))

This passes the integer value to the integer_to_reverse_binary function

integer_to_reverse_binary(integer_value)

You might be interested in
Which step is first in changing the proofing language of an entire document?
Genrish500 [490]
Select the whole document by pressing Ctrl+a.
7 0
3 years ago
Task 2
USPshnik [31]
4.
3.
1.
5.
2.
I rearranged them so the program would make sense by arranging the interaction in a logical order then placing input statements in between
6 0
2 years ago
Read 2 more answers
The Domain Name Service is what translates human-readable domain names into IP addresses that computers and routers understandA.
Mars2501 [29]

Answer:

True

Explanation:

A Domain Name Service comprises of computer servers that carries a database of public IP addresses and their related human-readable domain names/hostnames, it receives query as hostnames and helps to translates those human-readable domain names/hostnames into IP addresses that computers and routers understand.

5 0
3 years ago
Which of these is NOT a benefit of being connected 24/7?
Serjik [45]

Answer:

c

Explanation:

answering messages is a more of a choice than a benifit.

3 0
3 years ago
__________ delivers a comprehensive and accurate graphical overview of key performance indicators, often using a single screen.
Irina18 [472]
The answer is a digital dashboard.

In its simplest form, a digital dashboard or a business dashboard provides a graphical representation of KPIs, measures and metrics used by a company to monitor performance of departments, individuals, teams or the entire company. They track the progress of business objectives and make effective data driven decisions.



6 0
3 years ago
Other questions:
  • DLucy is planning to launch her podcast on career guidance for college students and has already recorded a few videos for market
    10·1 answer
  • What can you use with your keywords to narrow your search if you complete an internet search using a search engine and do not ge
    15·2 answers
  • Some IOS commands store passwords as clear text, but you can then encrypt the passwords with the service password-encryption glo
    10·1 answer
  • Which of these is an example of rebranding ?
    6·2 answers
  • A _______ policy states that the company may access, monitor, intercept, block access, inspect, copy, disclose, use, destroy, or
    5·1 answer
  • If you have 60fps on your laptop tell me one way you can go to 240fps
    14·2 answers
  • Write a C program that uses a while statement to determine and print the largest of 10 numbers input by the user. Your program s
    6·1 answer
  • g Assume that this program is run on a processor with data cache of size big enough that the entire array arr can fit in the cac
    5·1 answer
  • For which tasks is Layout view most helpful? Check all that apply.
    12·1 answer
  • A good algorithm should have which three components?
    10·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!