knowledge-database (beta)

Current group: comp.soft-sys.matlab

HEX to Float Single Precision

HEX to Float Single Precision  
Ricardo
 Re: HEX to Float Single Precision  
justin bourke
 Re: HEX to Float Single Precision  
Roger Stafford
From:Ricardo
Subject:HEX to Float Single Precision
Date:Sun, 23 Jan 2005 22:58:34 -0500
Hello,
I'm trying to convert float number (single precision) to hex and
back, hex to float but unfortunately have a problem using hex2num

x=-1.677e-6;
y=num2hex(single(x)); this part works ok
c=hex2num(y); ; this part returns double precision

any idea how to solve this problem
thanks,
Ric
From:justin bourke
Subject:Re: HEX to Float Single Precision
Date:Sun, 23 Jan 2005 23:44:44 -0500
Hi Ricardo,

Matlab works in double rather than single precision unless you ask it
otherwise. Your first line creates x as a double.

To convert something to single precision, all you need to do is call:

x=single(-1.677e-6);

Although I have never seen an application where hex numbers are used
in place of decimals.

Ricardo wrote:
>
>
> Hello,
> I'm trying to convert float number (single precision) to hex and
> back, hex to float but unfortunately have a problem using hex2num
>
> x=-1.677e-6;
> y=num2hex(single(x)); this part works ok
> c=hex2num(y); ; this part returns double precision
>
> any idea how to solve this problem
> thanks,
> Ric
From:Roger Stafford
Subject:Re: HEX to Float Single Precision
Date:Mon, 24 Jan 2005 07:55:18 GMT
In article , Ricardo
wrote:

> Hello,
> I'm trying to convert float number (single precision) to hex and
> back, hex to float but unfortunately have a problem using hex2num
>
> x=-1.677e-6;
> y=num2hex(single(x)); this part works ok
> c=hex2num(y); ; this part returns double precision
>
> any idea how to solve this problem
> thanks,
> Ric
------
do help hex2num.
It handles only double precision hex strings. If it receives an eight
character string it just appends eight more zeros to the right side of it,
which is not the way to make the conversion.
--
(Remove "xyzzy" and ".invalid" to send me email.)
Roger Stafford
   

Copyright © 2006 knowledge-database   -   All rights reserved