float to byte array?
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
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
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.
Example 1:
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:
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!]
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!]
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:
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
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
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement