Question

4. The following algorithm step 1: 20 := r; j :=0 step 2: while x; # 0, do d; := remainder of integer divide x;/2 Xj+1 := quo
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Matlab Code:

x=input('Enter the Decimal Number: ');
a=[];
while x~=0
a=[rem(x,2) a];
x=floor(x/2);
end
text1=['The Binary Representation is: ',num2str(a)];
disp(text1)

Testcase (i): 56

Enter the Decimal Number: 56
The Binary Representation is: 1 1 1 0 0 0

Testcase (ii): 1543

Enter the Decimal Number: 1543
The Binary Representation is: 1 1 0 0 0 0 0 0 1 1 1

Add a comment
Know the answer?
Add Answer to:
4. The following algorithm step 1: 20 := r; j :=0 step 2: while x; #...
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
  • Search for 4 in the sequence {3,5,7,8,9,12,21,25}, by working through each step of the algorithm given...

    Search for 4 in the sequence {3,5,7,8,9,12,21,25}, by working through each step of the algorithm given below. Specify the values of i, j, m and am in each step. procedure binary search (x: integer, a1,a2,...,an: increasing integers) i := 1 {i is left endpoint of search interval } j := n {j is right endpoint of search interval } while i < j m := b(i + j)/2c if x > am then i := m + 1 else j...

  • 9. (5 points) Please describe an algorithm that takes as input a list of n integers...

    9. (5 points) Please describe an algorithm that takes as input a list of n integers and finds the number of negative integers in the list. 10. (5 points) Please devise an algorithm that finds all modes. (Recall that a list of integers is nondecreasing if each term of the list is at least as large as the preceding term.) 11. (5 points) Please find the least integer n such that f() is 0(3") for each of these functions f()...

  • Consider the following algorithm: ocedure Algorithm (b: integer, n: positive integer,i datinct integem) proc answer :", 0 nand 6 while (j print(j, z, b, answer) if jSn then answer:-j return a...

    Consider the following algorithm: ocedure Algorithm (b: integer, n: positive integer,i datinct integem) proc answer :", 0 nand 6 while (j print(j, z, b, answer) if jSn then answer:-j return answer (8 points] Assume that this algorithm receives as input the numbers b-17 andn9nd the corresponding sequence or iaie i 2 3 4 516 7 8 corresponding sequence of integers 19 Fill out the table below: i 는, ↓answer (b) [I point] Assume that the algorithm receives the same input...

  • Copy of Consider the following algorithm: i+2 while (x mod i)=0 do iti+1 Now suppose x...

    Copy of Consider the following algorithm: i+2 while (x mod i)=0 do iti+1 Now suppose x is an element from the set {n EN|2sn s50). What is the worst-case number of comparisons that this algorithm will perform? O O O O O O

  • This is an assignment for my algorithm class which I have written the code partially and...

    This is an assignment for my algorithm class which I have written the code partially and only need to complete it by adding a time function that calculates the average running time. We could use any programming language we want so I am using C++. I am including the instruction and my partial code below. Thank you! Implement linearSearch(a,key) and binarySearch( a,key)functions. Part A.In this part we will calculate theaverage-case running time of each function.1.Request the user to enter a...

  • Do the following project: Following is the file to be programmed in Linux kernel. Run this...

    Do the following project: Following is the file to be programmed in Linux kernel. Run this program. Include the screenshot of the results. Multi threaded Sorting Application Write a multithreaded sorting program that works as follows: A list of integers is divided into two smaller lists of equal size. Two separate threads (which we will term sorting threads) sort each sub list using a sorting algorithm of your choice. The two sub lists are then merged by a third thread—a...

  • You need not run Python programs on a computer in solving the following problems. Place your...

    You need not run Python programs on a computer in solving the following problems. Place your answers into separate "text" files using the names indicated on each problem. Please create your text files using the same text editor that you use for your .py files. Answer submitted in another file format such as .doc, .pages, .rtf, or.pdf will lose least one point per problem! [1] 3 points Use file math.txt What is the precise output from the following code? bar...

  • This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation...

    This C++ Program consists of: operator overloading, as well as experience with managing dynamic memory allocation inside a class. Task One common limitation of programming languages is that the built-in types are limited to smaller finite ranges of storage. For instance, the built-in int type in C++ is 4 bytes in most systems today, allowing for about 4 billion different numbers. The regular int splits this range between positive and negative numbers, but even an unsigned int (assuming 4 bytes)...

  • Python Project

    AssignmentBitmap files map three 8-bit (1-byte) color channels per pixel. A pixel is a light-emitting "dot" on your screen. Whenever you buy a new monitor, you will see the pixel configuration by its width and height, such as 1920 x 1080 (1080p) or 3840x2160 (4K). This tells us that we have 1080 rows (height), and each row has 1920 (width) pixels.The bitmap file format is fairly straight forward where we tell the file what our width and height are. When...

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