Question: Program should be formated to run in Matlab. HINT: The way I handle the case when the input has a length less than 6 is

Program should be formated to run in Matlab.
HINT: The way I handle the case when the input has a length less than 6 is to have another variable that is initialized as '000000' and replace the suffix with the input binary number. For example, my input is x which has a value '100'. I'll need another variable y = '000000'. Then I can replace the suffix of y by x, i.e., y(4:6) = x. Now my y is '000100'. To handle variable length of input, you need to figure out the starting index of the suffix in terms of length(x).
CSCI 251 Section 3 Programming Assignment 2 Converting a Binary Number to Decimal Problem Statement Given a binary number of length at most 6, convert it to the decimal representation. For example, the binary number 100 is 4 in decimal. Do not use existing matlab function to do the conversion. The functions allowed for this assignment are: input(), str2num(), length() and fprintf). If you want to you functions not listed here, ask me for permission Input A binary number of length at most 6. But the length can be anything between 1 and 6 Output The number in decimal. If the length of the input is more than 6, give an error message Hint You can use the function length() to check the input length You can use leading O's if the length of the input is less than 6 Sample Outputs & Test Cases Test1 Enter the binary number: 100 The number in decimal is 4 Test2 Enter the binary number: 100100 The number in decimal is 36 Test3 The length of the binary number can not exceed 6 Program Complexity My solution code for this program is 13 lines. Notes Do not hard code the test cases. I may use other test cases not listed here to grade
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
