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
agasfer [191]
3 years ago
12

g 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 bin

ary. For an integer x, the algorithm is:
Engineering
1 answer:
Phoenix [80]3 years ago
4 0

Answer:

The solution is written in Python

  1. binary = ""
  2. decimal = 13
  3. quotient = int(decimal / 2)  
  4. remainder = decimal % 2
  5. binary = str(remainder) + binary
  6. while(quotient >0):
  7.    decimal = int(decimal / 2)
  8.    quotient = int(decimal / 2)  
  9.    remainder = decimal % 2
  10.    binary = str(remainder) + binary
  11. print(binary)

Explanation:

Firstly, we declare a variable <em>binary</em> and initialize it with an empty string (Line 1). This <em>binary </em>is to hold the binary string.

Next, we declare variable <em>decimal, quotient </em>and<em> remainder </em>(Line 2-4). We assign a test value 13 to decimal variable and then get the first quotient by dividing decimal with 2 (Line 3). Then we get the remainder by using modulus operator, % (Line 4). The first remainder will be the first digit joined with the binary string (Line 5).  

We need to repeat the process from Line 3-5 to get the following binary digits. Therefore create a while loop (Line 7) and set a condition that if quotient is bigger than 0 we keep dividing decimal by 2 and calculate the quotient and remainder and use the remainder as a binary digit and join it with binary string from the front (Line 9-11).

At last, we print the binary to terminal (Line 13).

You might be interested in
‏What is the potential energy in joules of a 12 kg ( mass ) at 25 m above a datum plane ?
Virty [35]

Answer:

E = 2940 J

Explanation:

It is given that,

Mass, m = 12 kg

Position at which the object is placed, h = 25 m

We need to find the potential energy of the mass. It is given by the formula as follows :

E = mgh

g is acceleration due to gravity

E=12\times 9.8\times 25\\\\E=2940\ J

So, the potential energy of the mass is 2940 J.

3 0
3 years ago
When moving cylinders always remove and make
Karolina [17]

Unless cylinders are firmly secured on a special carrier intended for this purpose, regulators shall be removed and valve protection caps put in place before cylinders are moved. A suitable cylinder truck, chain, or other steadying device shall be used to keep cylinders from being knocked over while in use.

5 0
4 years ago
Which of the following is a possible consequence of poor measurement in construction as stated in the segment?
Kamila [148]

Answer:

Decreased risk of structure failure

6 0
3 years ago
Should the ship breaking business continue why or why not?
Dmitry [639]

Answer:

Ship-breaking or ship demolition is a type of ship disposal involving the breaking up of ships for either a source of parts, which can be sold for re-use, or for the extraction of raw materials, chiefly scrap. It may also be known as ship dismantling, ship cracking, or ship recycling. Modern ships have a lifespan of 25 to 30 years before corrosion, metal fatigue and a lack of parts render them uneconomical to operate.[1] Ship-breaking allows the materials from the ship, especially steel, to be recycled and made into new products. This lowers the demand for mined iron ore and reduces energy use in the steel making process. Fixtures and other equipment on board the vessels can also be reused. While ship-breaking is sustainable, there are concerns about the use of poorer countries without stringent environmental legislation. It is also labor-intensive, and considered one of the world's most dangerous industries.[2]

In 2012, roughly 1,250 ocean ships were broken down, and their average age was 26 years.[3][4] In 2013, the world total of demolished ships amounted to 29,052,000 tonnes, 92% of which were demolished in Asia. As of January 2020, India has the largest global share at 30%;[5] followed by Bangladesh, China and Pakistan.[6] Alang, India currently has the world's largest ship graveyard,[5] followed by Chittagong Ship Breaking Yard in Bangladesh and Gadani in Pakistan.[6]

The largest sources of ships are states of China, Greece and Germany respectively, although there is a greater variation in the source of carriers versus their disposal.[7] The ship-breaking yards of India, Bangladesh, China and Pakistan employ 225,000 workers as well as providing many indirect jobs. In Bangladesh, the recycled steel covers 20% of the country's needs and in India it is almost 10%.[8]

As an alternative to ship-breaking, ships may be sunk to create artificial reefs after legally-mandated removal of hazardous materials, or sunk in deep ocean waters. Storage is a viable temporary option, whether on land or afloat, though all ships will be eventually scrapped, sunk, or preserved for museums.

6 0
3 years ago
In your first job with a large U.S based steel company, you have been assigned to a team tasked with developing a new low carbon
nignag [31]

Answer:

Option A

Explanation:

3 0
4 years ago
Read 2 more answers
Other questions:
  • 1. True or False: When two batteries are wired in Series the Volts go up and the Amp Hours stay the same. 2. True or False: When
    6·1 answer
  • Rosalind franklin<br> What was she famous for
    14·1 answer
  • At the grocery store you place a pumpkin with a mass of 12.5 lb on the produce spring scale. The spring in the scale operates su
    5·1 answer
  • What is Euler's equation?
    6·1 answer
  • Only an outer panel is being replaced. Technician A says that removing the spot welds by drilling through both panels allows the
    11·1 answer
  • . Bơm kiểu piston tác dụng đơn có áp suất p=0,64 Mpa và lưu lượng Q=3,5 l/s. Xác định tốc độ quay của trục bơm và công suất của
    7·1 answer
  • Random question, does anyone here use Lego, do not answer unless that is a yes
    15·2 answers
  • How can you contribute to achieved the mission of NSTP during pandemic in your society?
    7·1 answer
  • All of these are true about a magnesium part EXCEPT that it:
    8·1 answer
  • Technician A says the compressor is the dividing line of the refrigeration system, low- to high-side. Technician B says the expa
    6·1 answer
Add answer
Login
Not registered? Fast signup
Signup
Login Signup
Ask question!