🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: microsoft.public.vc.language
Article #101

Re: IEEE conversion: bytes into floating point number...

#101
From: joost witteveen
Date: Mon, 14 Jul 1997 00:00
48 lines
2353 bytes
In article <5qcobl$c5q@tuegate.tue.nl>, Eric Meijer wrote:
->dave (drs@cs.wisc.edu) wrote:
->: [G++ 2.7.2 or VC++ 4.0]
->
->: Greetings,
->
->: I need to convert a data string like this:
->
->: 	"111 134 27 240 249 33 9 64" (dec.)
->: 	"6F 86 1B F0 F9 21 09 40" (hex)         
->[... into a double precisionnumber ... ]
->
->What about
->
->------------------------------------------------------------------------
->#include <iostream.h"
->
->int main() {
->  signed char bytes={111,134,27,240,249,33,9,64};
->  double* d = (double *)bytes;
->  cout << bytes << endl;
->}
->------------------------------------------------------------------------
->
->If I compile this with g++ 2.7.2, It prints 3.14159.  That looks like a
->non random number to me.  I wouldn't claim this is any portable, but it
->does seem to work.

The above must be an old version of your attempt -- or you've got
a _very_ non-portable g++ compiler!

This works better (and does print 3.14159):
------------------------------------------------------------------------
#include <iostream.h>

int main() {
  signed char bytes[]={111,134,27,240,249,33,9,64};
  double* d = (double *)bytes;
  cout << *d << endl;
}
------------------------------------------------------------------------
-- 
joost witteveen, joostje@debian.org
#!/usr/bin/perl -sp0777i<X+d*lMLa^*lN%0]dsXx++lMlN/dsM0<j]dsj
$/=unpack('H*',$_);$_=`echo 16dio\U$k"SK$/SM$n\EsN0p[lN*1
lK[d2%Sa2/d0$^Ixp"|dc`;s/\W//g;$_=pack('H*',/((..)*)$/)
#what's this? see http://www.dcs.ex.ac.uk/~aba/rsa/
Technical Details
Message-ID: <slrn5skocu.m0g.joost@rulcmc.leidenuniv.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <33C83D2D.4528@cs.wisc.edu> <5qcobl$c5q@tuegate.tue.nl>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII-7-bit
X-Google-Thread: f7a51,c41b066001ba50e9
X-Google-Attributes: gidf7a51,public
X-Google-Thread: 109fba,c41b066001ba50e9
X-Google-Attributes: gid109fba,public
X-Google-Thread: 1014db,c41b066001ba50e9
X-Google-Attributes: gid1014db,public
X-Google-Thread: 10ba33,c41b066001ba50e9
X-Google-Attributes: gid10ba33,public
From: joost@rulcmc.leidenuniv.nl (joost witteveen)
Subject: Re: IEEE conversion: bytes into floating point number...
Date: 1997/07/14
Message-ID: <slrn5skocu.m0g.joost@rulcmc.leidenuniv.nl>
X-Deja-AN: 256823286
References: <33C83D2D.4528@cs.wisc.edu> <5qcobl$c5q@tuegate.tue.nl>
Organization: Leiden University, The Netherlands
Newsgroups: microsoft.public.vc.language,comp.lang.c,comp.lang.c++,gnu.g++.help