For this part of the project, using Matlab you will need to write a function tha
ID: 1840345 • Letter: F
Question
For this part of the project, using Matlab you will need to write a function that has one input argument and one output argument. The input is any decimal number. The output will be a vector of 1s and 0s representing the double precision IEE754 notation of the number.
For this section the only special case you need to account for is zero. You can choose to whether it is positive or negative. Otherwise, as long as the number is in range, it should be converted to the Normalized form and output as a vector of 1s and 0s – 64 digits long (see the table Floating
1
Explanation / Answer
Didnot mention the table. Leave comments for any clarifications. Thank You.
Main Program (Main_Prog_Convertion_iee754.m):
clc;
close all;
X = input('Enter the Decimal Number:');% Reading the decimal number from command window
output_64bit_form = Convertion_iee754(X);% Calling function program "Convertion_iee754"
disp('The IEE754 form of given number is:');
disp(output_64bit_form); % Displaying output in command window
Function Program (Convertion_iee754.m):
function [bitstr] = Convertion_iee754(X)
% except for special values 0, Inf, NaN, and denormalized numbers(between
% 0 and REALMIN)
if ~isreal(X) || numel(X) > 1 || ~isa(X,'double') % Checking improper formats of input
error('Please enter a Real Scalar in Decimal form') % Display error dialogue
end
hex = num2hex(X); % string of 16 hex digits for x
dec = hex2dec(hex'); % decimal for each digit (1 per row)
bin = dec2bin(dec,4); % 4 binary digits per row
bitstr = reshape(bin',[1 64]); % string of 64 bits in order
% Return options
if nargout<2
s = bitstr;
else
s = bitstr(1); % Indicates Sign
e = bitstr(2:12); % Indicates Exponent
f = bitstr(13:64); % Indicates Floating Point
if nargin > 1 && isequal(lower(fmt),'dec')
s = bin2dec(s); e = bin2dec(e); f = bin2dec(f);
end
end
The output for two different inputs +5 and -7 are as follows:
Enter the Decimal Number:5
The IEE754 form of given number is:
0100000000010100000000000000000000000000000000000000000000000000
>> Main_Prog_Convertion_iee754
Enter the Decimal Number:-7
The IEE754 form of given number is:
1100000000011100000000000000000000000000000000000000000000000000
Related Questions
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.