From: buers AT gmx DOT de (Dieter Buerssner) Newsgroups: comp.os.msdos.djgpp Subject: Re: binary to float Date: 23 Feb 2000 14:34:30 GMT Lines: 28 Message-ID: <890r5l$1qjno$1@fu-berlin.de> References: <389C5256 DOT B1EFBC69 AT gmx DOT at> <890hch$49b$1 AT news DOT inet DOT tele DOT dk> NNTP-Posting-Host: dialup-212.162.14.54.frankfurt1.mik.net (212.162.14.54) Mime-Version: 1.0 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 8bit X-Trace: fu-berlin.de 951316470 1920760 212.162.14.54 (16 [17104]) X-Posting-Agent: Hamster/1.3.13.0 User-Agent: Xnews/03.02.04 To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Reply-To: djgpp AT delorie DOT com Neohashi AT mail DOT tele DOT dk (neohashi) wrote in <890hch$49b$1 AT news DOT inet DOT tele DOT dk>: >Can any one explain to me how do I get 4 bytes(IEEE float) into a >floating point var? (it need to be reversed to) DJGPP uses the IEEE-formats, i.e. type float is 4 byte IEEE float. The only problem may arise from the endianess of the format. If you have to swap endianess, the following code snippet may work. (untested) FILE *fp; unsigned char rawdata[4]; unsigned char t; float x; fp = fopen("binfloat.dat", "rb"); if (fp) { if (fread(rawdata, sizeof rawdata, 1, fp) == 1) { /* swap endianess */ t = rawdata[0]; rawdata[0] = rawdata[3]; rawdata[3] = t; t = rawdata[1]; rawdata[1] = rawdata[2]; rawdata[2] = t; x = *(float *)rawdata; /* x is the float you wanted */ } } Dieter