• Advertisement

Archived

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

Typecasting floats..

This topic is 6450 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

Hi, this is my first post here and I''m hoping somebody can help me with this little quirk I''ve run up against.. I have a char pointer to a big chunk of memory representing a file that''s been loaded into RAM. To get a value from this memory, I''ll combine the bytes and increment the pointer.. e.g., for a 16-bit integer, I''d use "MAKEWORD ( *ptr, *(ptr+1) ); ptr+=2;" The problem comes into play when I try to load a float. I tried typecasting a 32-bit integer, but that only results in x.0000000 (where X is the 32-bit integer). I''m surprised that I''m stumped at such a simple problem, but that''s the nature of being stumped. Thanks for any help. - RWarden (roberte@maui.net)

Share this post


Link to post
Share on other sites
Advertisement
You might try memcpy() to copy four bytes from ptr to the address of the float variable.

- MK42

Share this post


Link to post
Share on other sites
Also, you can always use a void pointer to defeat the translations that occur in a word to float typecast.

-RotoMuffin

Share this post


Link to post
Share on other sites

float f = *( (float*) (charptr+charoffs) );

Should do the trick. Aren''t typecasts so beautiful?-)

Share this post


Link to post
Share on other sites

  • Advertisement