Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Follow the MATLAB Template provided please for Question1: MATLAB Template: %Problem 1 %Arrays representing the four binary numbers to be converted to decimal b1= [1

Follow the MATLAB Template provided please for Question1:

image text in transcribed

MATLAB Template:

%Problem 1

%Arrays representing the four binary numbers to be converted to decimal b1= [1 0 1 1 0 1 1 0 0 0 1 0 0 0 0 0 0 1 1 1 1 0 0 0 1 1 1 1 0 0 0 1]; b2 = ones(1,32); b3 = [1, zeros(1,31)]; b4 = [1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 ];

%character array equivalents for use with bin2dec c1='10110110001000000111100011110001'; c2='1111 1111 1111 1111 1111 1111 1111 1111'; c3 = '1000 0000 0000 0000 0000 0000 0000 0000'; c4 = '1010 1010 1010 1010 1010 1010 1010 1010';

1. Binary-to-decimal conversion The decimal value of a binary number is calculated from the equation X = 0,21 E Where b, is the nth bit (either 0 or 1) and N is the number of bits in the binary number. As an illustrative example, the binary number 1010 0110 has the decimal value X = 1.27 +0.26 +1.25 +0.24 +0.22 + 1.22 +1.24 +0.2 = 128 +32 + 4 + 2 = 166 A. Write a script to calculate the decimal value of a 32-bit binary number by the following method: a. Create a row vector, n, containing the integers from 31 through O in descending order. (Do not type all 32 numbers - use the operator or linsrace.) b. Create a row vector of Os and 1s representing the bits of the binary number. (For the example given above, the row vector would be b = [1, 0, 1, 0, 0, 1, 1, 0]) C. Perform element-by-element array operations to create a row vector containing the terms b, 2". d. Use the sum function to calculate X. Test your method on the following numbers (helpfully provided in the template): 1011 0110 0010 0000 0111 1000 1111 0001 1111 1111 1111 1111 1111 1111 1111 1111 1000 0000 0000 0000 0000 0000 0000 0000 1010 1010 1010 1010 1010 1010 1010 1010 B. Use the built-in function, bin2 dec (), to check your answers, and include these checks in your script. (But note that the input argument of bin2 dec is a character array, not a numerical array.) C. Of the four decimal values that you calculated in part A, calculate the ratio of the second number to the third one and look at the result. It shows an interesting property of binary numbers

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

Database Theory Icdt 99 7th International Conference Jerusalem Israel January 10 12 1999 Proceedings Lncs 1540

Authors: Catriel Beeri ,Peter Buneman

1st Edition

3540654526, 978-3540654520

Students also viewed these Databases questions