HUGE JAVA/C++ PROBLEM!

Started by
22 comments, last by Enigma 18 years, 6 months ago
Quote:Original post by TempHolder
Ok but can anyone give me a working example on how to reconstruct a float with 4 bytes?, because it isnt as easy as the interger when I tried it.


It is as easy as with an integer. A float is 4 bytes too. So instead of reading a float, you read an integer, then process it using s_p_oneil's code, then you use this little one-line inlined function:

inline float from_int(int i){  return *((float *)(&i));}


First, it takes the address of i and modify the type of the pointer to (float*). Then it dereference the pointed variable (which end up beeing a float).

This is not a cast from int to float, because the binary value don't change.

HTH,
Advertisement
cool thanks, but I found another way to do it as well, but yours looks shorter so ill probally use.
Edit: Body removed as the information I gave wasn't proper.

[Edited by - private_ctor on October 6, 2005 2:19:53 PM]
-------------------------------Sometimes I ~self();
Quote:Original post by private_ctor
//A slow, technically undefined swap method between bytes would beb[0] ^= b[3] ^= b[0] ^= b[3];  b[1] ^= b[2] ^= b[1] ^= b[2];

Fixed.

Enigma

This topic is closed to new replies.

Advertisement