```Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: decimal fraction to binary conversion
Date: Tue, 20 Dec 2011 07:03:08 +0000 (UTC)
Organization: The MathWorks, Inc.
Lines: 27
Message-ID: <jcpbvc\$rr0\$1@newscl01ah.mathworks.com>
References: <jbab7h\$47b\$1@newscl01ah.mathworks.com> <jbbfnl\$8v6\$1@newscl01ah.mathworks.com>
NNTP-Posting-Host: www-06-blr.mathworks.com
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: newscl01ah.mathworks.com 1324364588 28512 172.30.248.38 (20 Dec 2011 07:03:08 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Tue, 20 Dec 2011 07:03:08 +0000 (UTC)
Xref: news.mathworks.com comp.soft-sys.matlab:752747

"Roger Stafford" wrote in message <jbbfnl\$8v6\$1@newscl01ah.mathworks.com>...
> "hend " <eng.hr2009@yahoo.com> wrote in message <jbab7h\$47b\$1@newscl01ah.mathworks.com>...
> > i'm in need to a program code which can convert negative fractions into binary form ( any form )  ..
> > dec2bin command is not helpful in this case !
> - - - - - - - - -
>   You can use 'dec2bin' if you help it out a bit.  As an example, suppose you want to display 16 fractional binary digits on the number -1/(4*pi).
>
>  d = 16;
>  x = -1/(4*pi);
>
>  b = sign(x);
>  t = round(2^d*abs(x));
>  [~,e] = log2(t);
>  s = dec2bin(t,max(d,e));
>  s = [s(1:end-d),'.',s(end-d+1:end)];
>  if b<0, s = ['-',s]; end
>
> The string s is the result.  This code may not be quite the format you want but if not perhaps you can modify it appropriately.
>
> Roger Stafford

Hi Roger,

How will you convert the negative fractional binary number back to the decimal number?

With regards,
Shyamsunder
```