Thread: float value storage

  1. #1
    Registered User
    Join Date
    Aug 2008
    Posts
    17

    float value storage

    hi,
    Can anyone please explain....how a float value is stored in memory.

    For example.

    The sizeof float value is 4 bytes ie) 32bits.....

    If a=32.56

    The binary equivalent of 32.56 is 100000.100011111

    How this is stored in 4 bytes....

    Whether it is like this ????

    First two bytes for decimal part and next two bytes for fractinal part...

    Please explain me .....how a float value is stored in memory using 4 bytes....

    Regards,
    Rohit

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    Search the Web for "IEEE 754" for the most common example.
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Technical Lead QuantumPete's Avatar
    Join Date
    Aug 2007
    Location
    London, UK
    Posts
    894
    Like laserlight alluded, there are actually several different ways of storing floating point numbers. Usually (due to the "floating" point). the number of bytes for the decimal and fractional part are not set, they vary from number to number. That's why it is often impossible to represent numbers accurately that have a huge decimal part and a large fractional part. So you can for example display a number to 20 decimal places, but once you add 10,000,000 to that, you're going to lose precision in the fractional part.

    QuantumPete
    "No-one else has reported this problem, you're either crazy or a liar" - Dogbert Technical Support
    "Have you tried turning it off and on again?" - The IT Crowd

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 2
    Last Post: 05-13-2009, 03:25 PM
  2. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM
  3. Could somebody please help me with this C program
    By brett73 in forum C Programming
    Replies: 6
    Last Post: 11-25-2004, 02:19 AM
  4. Half-life SDK, where are the constants?
    By bennyandthejets in forum Game Programming
    Replies: 29
    Last Post: 08-25-2003, 11:58 AM
  5. How do you search & sort an array?
    By sketchit in forum C Programming
    Replies: 30
    Last Post: 11-03-2001, 05:26 PM