Question: Using MATLAB , please provide code to do the following: (a) Write a function that takes a binary number as its argument and returns its

Using MATLAB, please provide code to do the following:

(a) Write a function that takes a binary number as its argument and returns its decimal equivalent. A binary number is a number that does not have any digits other than 0 and 1. The rightmost digit has the value 20 and the digit N places to the left of that has the value 2N. For example, entering 1010101 returns 85 = 26+24+22+20. If a number containing a digit other than 0 and 1 is given as an argument to this function, it must display an error message. You must use a loop to solve this problem

(b) Write a function that takes a positive integer (decimal) number as argument and returns its binary value using the repeated division-by-2 method. In this method, the decimal number is continually divided by 2 to give a result and a remainder of 0 or 1 until the final result is 0.

Example:

Using MATLAB, please provide code to do the following: (a) Write a

The remainders from MSB to LSB give the binary value of the number: 1010110

If the user enters a fractional value or a number less than 0, an error message should be displayed to the user.

Number 86 Divide by 2 Result 43 Result 21 Result 10 Result 5 Result 2 Result 1 Result 0 Remainder 0 (LSB) Remainder 1 Remainder 1 Remainder 0 Remainder 1 Remainder 0 Remainder 1 (MSB) Number 86 Divide by 2 Result 43 Result 21 Result 10 Result 5 Result 2 Result 1 Result 0 Remainder 0 (LSB) Remainder 1 Remainder 1 Remainder 0 Remainder 1 Remainder 0 Remainder 1 (MSB)

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!