Xref: news2.mv.net comp.os.msdos.djgpp:758 From: Erik Max Francis Newsgroups: comp.os.msdos.djgpp Subject: Re: binary representation of floats Date: Fri, 02 Feb 1996 12:29:56 -0800 Organization: &tSftDotIotE Lines: 26 Message-ID: <31127444.7DE259CD@alcyone.com> References: NNTP-Posting-Host: newton.alcyone.com To: djgpp AT delorie DOT com DJ-Gateway: from newsgroup comp.os.msdos.djgpp Eli Zaretskii wrote: > Every book on Intel CPUs describes this. To get a bit pattern of any > float or double variable, cast them to an unsigned int and use the usual > bit operations. (In the case of double, you'll have to use long long.) Correct me if I'm mistaken, Eli, but this won't work. Casting a float or double to an integer type will truncate the value so that it is the nearest integer less than or equal to the float/double value. That is, (unsigned int) 2.1f yields 2, not the binary representation of 2.1 in the machine's float. What you have to do is cast a _pointer_ to that float or integer to a pointer of an integral type of the same size. That is, instead of (unsigned int) f, you need *(unsigned int *) &f. -- Erik Max Francis, &tSftDotIotE. && max AT alcyone DOT darkside DOT com || max AT alcyone DOT com San Jose, California, U.S.A. && 37 20 07 N 121 53 38 W && the 4th R is respect H.3`S,3,P,3$S,#$Q,C`Q,3,P,3$S,#$Q,3`Q,3,P,C$Q,#(Q.#`-"C`- && 1love && folasade Omnia quia sunt, lumina sunt. && GIGO Omega Psi && http://www.alcyone.com/max/ "Out from his breast/his soul went to seek/the doom of the just." -- _Beowulf_