Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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:

image text in transcribed

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

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

Step: 3

blur-text-image

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

Guide To Client Server Databases

Authors: Joe Salemi

2nd Edition

1562763105, 978-1562763107

More Books

Students also viewed these Databases questions

Question

What is the growth rate of GDP per capita?

Answered: 1 week ago