🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

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

#102
From: Eric Meijer
Date: Tue, 15 Jul 1997 00:00
53 lines
2428 bytes
joost witteveen (joost@rulcmc.leidenuniv.nl) wrote:
: 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;
: }

>blush<

Well, er yes, that was it.  (Monday mornings were never my best)

Eric

--
 E.L. Meijer
 Eindhoven Univ. of Technology
 Lab. for Catalysis and Inorg. Chem.
Technical Details
Message-ID: <5qfal7$4m@tuegate.tue.nl>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <33C83D2D.4528@cs.wisc.edu> <5qcobl$c5q@tuegate.tue.nl> <slrn5skocu.m0g.joost@rulcmc.leidenuniv.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: 10ba33,c41b066001ba50e9
X-Google-Attributes: gid10ba33,public
X-Google-Thread: 1014db,c41b066001ba50e9
X-Google-Attributes: gid1014db,public
From: tgakem@sg14.chem.tue.nl (Eric Meijer)
Subject: Re: IEEE conversion: bytes into floating point number...
Date: 1997/07/15
Message-ID: <5qfal7$4m@tuegate.tue.nl>
X-Deja-AN: 256952646
References: <33C83D2D.4528@cs.wisc.edu> <5qcobl$c5q@tuegate.tue.nl> <slrn5skocu.m0g.joost@rulcmc.leidenuniv.nl>
Followup-To: microsoft.public.vc.language,comp.lang.c,comp.lang.c++,gnu.g++.help
Organization: Eindhoven University of Technology, The Netherlands
Newsgroups: microsoft.public.vc.language,comp.lang.c,comp.lang.c++,gnu.g++.help