We help IT Professionals succeed at work.

float to int bits

css
css asked
on
Hi,
I'm searching for a function similar to FloatToIntBits used in Java for Float types (it converts a float into an int so bits stay the same).
Can you help me?
Comment
Watch Question

Commented:
float grr;
grr = 1.11f;
__int32 grr2;
memcpy(&grr2, &grr, sizeof(float));

memcpy just copies the raw bits from one place to another.  It's not good practice to do this kind of thing, but it'll work for what you want.  Note that you'll need a 32 bit int.
or if you need this often (and have a decent compiler),
__int32 intie = *(__int32 *)&floatie;
*tends* to produce better code

Explore More ContentExplore courses, solutions, and other research materials related to this topic.