Path: news.mathworks.com!newsfeed-00.mathworks.com!solaris.cc.vt.edu!news.vt.edu!news.glorb.com!npeer02.iad.highwinds-media.com!news.highwinds-media.com!feed-me.highwinds-media.com!postnews.google.com!y10g2000prc.googlegroups.com!not-for-mail
From: Sheng <szhangut@gmail.com>
Newsgroups: comp.soft-sys.matlab
Subject: Fixed point number conversion
Date: Wed, 6 May 2009 09:55:46 -0700 (PDT)
Organization: http://groups.google.com
Lines: 33
Message-ID: <663d3f25-8454-44c2-9b72-bfecfeddd9ed@y10g2000prc.googlegroups.com>
NNTP-Posting-Host: 128.62.121.79
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-1
Content-Transfer-Encoding: 7bit
X-Trace: posting.google.com 1241628946 25888 127.0.0.1 (6 May 2009 16:55:46 GMT)
X-Complaints-To: groups-abuse@google.com
NNTP-Posting-Date: Wed, 6 May 2009 16:55:46 +0000 (UTC)
Complaints-To: groups-abuse@google.com
Injection-Info: y10g2000prc.googlegroups.com; posting-host=128.62.121.79; 
	posting-account=0GK00woAAAA0COt3c02w494aHXQU7NiX
User-Agent: G2/1.0
X-HTTP-UserAgent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.0.10) 
	Gecko/2009042523 Ubuntu/9.04 (jaunty) Firefox/3.0.10,gzip(gfe),gzip(gfe)
Xref: news.mathworks.com comp.soft-sys.matlab:537950


Hi

I have a problem about fixed point conversion.

I know that use fi toolbox I can convert a dec. number into a hex.
format, like this

>> format hex
>> fi(pi, 1,32,29)

ans =

6487ed51

          DataTypeMode: Fixed-point: binary point scaling
                Signed: true
            WordLength: 32
        FractionLength: 29

             RoundMode: nearest
          OverflowMode: saturate
           ProductMode: FullPrecision
  MaxProductWordLength: 128
               SumMode: FullPrecision
      MaxSumWordLength: 128
         CastBeforeSum: true

But how do I convert back from 6487ed51 to pi?
For positive number, I can do hex2dec('6487ed51')/2^29, result is pi.
But when the number is negative, the hex number is 2's complement, so
I can't use hex2dec.

Any suggestion?