Results 1 to 6 of 6

Thread: Newbie 4 Byte Question

  1. #1

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    45

    Newbie 4 Byte Question

    Hi !

    In a programming lesson we had the following :
    a)"What's the highest value that can be stored within a 4-Byte float ?"

    answer: (2^31)-1.

    Why is it not 2^32 ?
    Or why is it not (2^32)-1 ??



    b)"What's the smallest value that can be stored within a 4-Byte float ?"

    answer: -2^31

    ???


    Can anybody help me with that ?
    btw i know that 4 Byte are 32 Bit

    Thanks
    Tom

  2. #2
    Lively Member
    Join Date
    Nov 2000
    Location
    Québec City
    Posts
    73
    Are you really talking about floats? floating point numbers?

    I'm asking this because the max value for a single precision floating point number is
    3.402823E38
    which isn't related to 2^32 in any way...

    Are you sure you're not talking about 4 byte integers? (long or double depending on the language)

  3. #3
    Zaei
    Guest
    Yeah, if dealing with real floating point values, its wrong. if dealing with integer values:

    The answer is because you are using a signed value. 4 bytes == 32 bits. If you were to use all 32 bits, you would have 2^32. But, since you are using a signed value, one bit is used as the sign bit, leaving only 31 bits, 2^31. The -1 comes from the fact that 0 is positive, so you cannot store the value 2^31. Since 0 is not negative, you CAN store -2^31.

    Z.

  4. #4
    Zaei
    Guest
    In what language is a double an integer value?

    Z.

  5. #5
    Stuck in the 80s The Hobo's Avatar
    Join Date
    Jul 2001
    Location
    Michigan
    Posts
    7,256
    Originally posted by Zaei
    In what language is a double an integer value?

    Z.
    Spanish.
    My evil laugh has a squeak in it.

    kristopherwilson.com

  6. #6

    Thread Starter
    Member
    Join Date
    Feb 2002
    Posts
    45
    Thanks Zaei !

    I can understand now ! Cool !!

    He really asked for a 4Byte float - checked it again !
    Don't know if he refered to C++ ? (What we're doing )

    Thanks !

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width