Mail Archives: djgpp/2000/02/23/13:53:27
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
- Raw text -