1. Not finding help here? Sign up for a free 30min tutor trial with Chegg Tutors
    Dismiss Notice
Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

MATLAB Function

  1. Oct 21, 2012 #1
    1. The problem statement, all variables and given/known data

    The problem asks us to write a MATLAB function that takes as input a vector 'v' representing a 64-bit machine number in double precision, and extract the sign (t), the exponent (c), and the mantissa (f).

    2. Relevant equations



    3. The attempt at a solution

    I'm extremely novice at MATLAB and the instructor assigned us a HW and a tutorial without bothering to pass on lectures about the language so bear with me, please.

    Code (Text):
    function [t c f] = GetVector(v)
    t = v(1);
    c = v(2:12);
    f = v(13:64);
    end
    Now, t will take the values 0 or 1 (the first element of the 64-bit representation), c will take the next 11 bits (the biased exponent), and f takes the remaining 52 bits. Now, my question is, do we have to subtract 1023 from the biased exponent to get e (the exponent) since they asked for the exponent? How exactly do we do that?

    I think we have to create another function that converts the binary representation of c into decimal form then subtract 1023 from the 10-based number. If so, will this function do? And how exactly do functions return a value in MATLAB?

    Code (Text):
    function [dec] = Convert2to10(Ibase2)
    for i = 1 : length(Ibase2)
        dec = dec + str2num(Ibase2(i)) * 2^(length(Ibase2) - i);
    end
    end
    Thanks in advance.
     
  2. jcsd
Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook

Can you offer guidance or do you also need help?