Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Use Scratch to create a program that converts a decimal number to the equivalent 8-bit unsigned binary number. In class, we have discussed two strategies

image text in transcribed

Use Scratch to create a program that converts a decimal number to the equivalent 8-bit unsigned binary number. In class, we have discussed two strategies for performing this conversion: Powers-of-two strategy: Is the decimal number greater than or equal to 128? If so, subtract 128 from the decimal number and put a 1 as the most significant bit (MSB). If not, put a 0 as the MSB. Is the new decimal number greater than or equal to 64? If so, subtract 64 from the decimal number and put a 1 as the next bit to the right of the MSB. If not, put a O as the next bit to the right of the MSB. And, so on, until the least significant bit (LSB) has been filled with a 1 or a O Repeated-division-by-2 strategy: Divide the decimal number by 2. Put the remainder as the LSB. Replace the decimal number with the quotient. Divide this new decimal number by 2. Put the remainder as the next bit to the left of the LSB. Replace the decimal number with the quotient. And, so on, until the quotient is O The following are some notes about your program: The program should get the decimal number to be converted as user input (i.e., use the "ask" command). .If the user inputs a decimal number that is out of range (see Question 1 below), display an appropriate error message and nothing else. The program should display the binary number all at once with the MSB on the left and the LSB on the right. That is DO NOT display the bits one at a time. Use the "join" operation to form a single string from two sources. Don't forget to display exactly 8 bits. You may need to add "leading Os" on the left to accomplish this. Don't make this problem harder than it is! Take advantage of the fact that the program should convert to a binary number with exactly 8 bits. This means that you are dealing with just eight powers of two-128, 64, 32, 16, 8, 4, 2 1. Use Scratch to create a program that converts a decimal number to the equivalent 8-bit unsigned binary number. In class, we have discussed two strategies for performing this conversion: Powers-of-two strategy: Is the decimal number greater than or equal to 128? If so, subtract 128 from the decimal number and put a 1 as the most significant bit (MSB). If not, put a 0 as the MSB. Is the new decimal number greater than or equal to 64? If so, subtract 64 from the decimal number and put a 1 as the next bit to the right of the MSB. If not, put a O as the next bit to the right of the MSB. And, so on, until the least significant bit (LSB) has been filled with a 1 or a O Repeated-division-by-2 strategy: Divide the decimal number by 2. Put the remainder as the LSB. Replace the decimal number with the quotient. Divide this new decimal number by 2. Put the remainder as the next bit to the left of the LSB. Replace the decimal number with the quotient. And, so on, until the quotient is O The following are some notes about your program: The program should get the decimal number to be converted as user input (i.e., use the "ask" command). .If the user inputs a decimal number that is out of range (see Question 1 below), display an appropriate error message and nothing else. The program should display the binary number all at once with the MSB on the left and the LSB on the right. That is DO NOT display the bits one at a time. Use the "join" operation to form a single string from two sources. Don't forget to display exactly 8 bits. You may need to add "leading Os" on the left to accomplish this. Don't make this problem harder than it is! Take advantage of the fact that the program should convert to a binary number with exactly 8 bits. This means that you are dealing with just eight powers of two-128, 64, 32, 16, 8, 4, 2 1

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Navigating The Supply Chain Maze A Comprehensive Guide To Optimize Operations And Drive Success

Authors: Michael E Kirshteyn Ph D

1st Edition

B0CPQ2RBYC, 979-8870727585

Students also viewed these Databases questions

Question

What things do (and do not) predict self-reported happiness?

Answered: 1 week ago

Question

Tell the merits and demerits of Mendeleev's periodic table.

Answered: 1 week ago

Question

4. How has e-commerce affected business-to-business transactions?

Answered: 1 week ago