Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


float to byte array?

This topic is 6110 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

What would you like in those bytes?

The x86 op code fbstp will convert a floating point type into an array of packed BCDs.

Edited by - Magmai Kai Holmlor on December 30, 2001 5:03:11 AM

Share this post

Link to post
Share on other sites
bleh...i was hoping to be able to do it without asm...what im used to doing with integers is to just shift the bits and put it into a byte. since you cant do this with a float, im trying to find a way.

Share this post

Link to post
Share on other sites
Example 1:
union {
float F;
int I;
} MyIntFloat;

Whatever you set F to, I shares the same memory, so you can treat it like an integer. You could also do "unsigned char B[4];" instead of the integer (remember that x86 CPU''s are little endian). Example 2:
float F;
int I = *((int *)&F);

I now equals the data within F. There are more methods, but they aren''t as good as those two.

[Resist Windows XP''s Invasive Production Activation Technology!]

Share this post

Link to post
Share on other sites
what are you trying to do this for? you can do this without asm. just look up the IEEE spec for floats and doubles. its just a matter of following the spec. you can use arrays.

example PSEUDO code:

unsigned char floatArray[sizeof(float)];
float theFloat;

// now you can manipulate by:

memcpy(floatArray, &theFloat, sizeof(float));
// or if you are brave use type casting (a bit messy)

((unsigned char *)(&theFloat))[idx];

just remeber floating point numbers have a format to follow. so make sure you look it up. it owuld be best to explain what you need this for.

you can do the same with doubles

Edited by - a person on December 30, 2001 6:20:16 PM

Share this post

Link to post
Share on other sites

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!