Thread: Integer to 32-bit Float?

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Registered User
    Join Date
    Apr 2006
    Posts
    2,149
    Quote Originally Posted by robwhit View Post
    I think you should download one of the C draft standards in the sticky because some of these online references aren't really complete when it comes to format specifiers. For example, %x is for an unsigned it, not a float.

    http://linux.die.net/man/3/strtof
    Actually he's got that part right. He reads in an integer into a 4 bit value that he later reinterprets as a float. The type of i and f have no bearing here, as long as they are 4 bytes. In fact, an array of 4 chars may be the best type since that's guaranteed to be 4 bytes.

    The results are predictable, but not well defined. Unfortunately I don't see a well defined way of doing this in C (unlike C++).
    Last edited by King Mir; 09-09-2008 at 08:39 PM.
    It is too clear and so it is hard to see.
    A dunce once searched for fire with a lighted lantern.
    Had he known what fire was,
    He could have cooked his rice much sooner.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Link List math
    By t014y in forum C Programming
    Replies: 17
    Last Post: 02-20-2009, 06:55 PM
  2. Float Function Issues
    By GCNDoug in forum C++ Programming
    Replies: 5
    Last Post: 10-29-2007, 03:25 PM
  3. porting application from 32 bit to 64 bit error
    By gandalf_bar in forum Linux Programming
    Replies: 1
    Last Post: 09-14-2005, 09:20 AM
  4. Need more eyes to find problem??
    By sailci in forum C++ Programming
    Replies: 2
    Last Post: 03-24-2002, 10:03 PM