Results 1 to 4 of 4

Thread: Do Doubles/Singles really look like this?

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151
    Do to another Query, I started trying to determine the algorithm for conversion to Double, and the appearance of doubles in memory.

    Not wanting to reinvent the wheel, I checked a few Web Sites, but was unable to find a precise description of double variables (The IEEE site did not have a readily available description, even though that organization is responsible for the specifications).

    I developed a simple VB application which accepted some input data, converted to Doubles, singles, and Longs (if possible), and wrote to a file. I then investigated the file using a Hex Editor (The one supplied with Ztree).

    Here are some results. Do you believe them? If not, can you provide the Doubles and singles corresponding to my Decimal values? Better yet, do you know the algorithm which describes conversion of decimal data to double/single? I think 9 or 10 bits of a double make an exponent and the rest comprise a binary value.

    Decimal 450,123 (Hex 6D,E4B) results in Long: 4BDE 0600
    Corresponding Double: 0000 0000 2C79 1B41
    Corresponding Single: 60C9 DB48

    Integers and Longs arrange the digits differently than a human being would, but the algorithm is fairly obvious. It boggled my mind when I compared doubles with correspondiing Singles, and found no obvious correlation. This makes me wonder about possible bugs in my application and/or makes me suspect my Hex Editor.

    Decimal .0001 (Hex .0006 8DB8 BAC7 1CA, I think).
    Corresponding double: 2D43 1CEB E236 1A3F
    Corresponding Single: 17B7 D138

    If interested, I have other data ([email protected]), including some powers of two, integers 1-9, fractional powers of two (EG: 1/2, 1/4, 1/8), and other values. These examples provide some clues, but I have not yet figured out what is happening.

    I expected to see something obvious, and am wondering if my VB application or the Hex Editor have errors.

    Thanx for help --- Gouverneur Cadwallader (Dinosaur from prehistoric Mainfame era)

  2. #2
    Member
    Join Date
    Mar 2000
    Location
    Colorado
    Posts
    39
    Are you using the CDbl() (converts to a double), CSng() (converts to a single), etc. functions that convert one data type to another?

    LauRa
    LauRa
    "Work like you don't need the money...Love like you've never been hurt...Dance like nobody is watching..."

  3. #3

    Thread Starter
    Frenzied Member
    Join Date
    Jul 1999
    Location
    Huntingdon Valley, PA 19006
    Posts
    1,151

    Yes, I used CDbl & CSng

    Answer to question posed in first reply.

    I used standard VB conversion functions (CDbl, CSng, Clng), a common dialog box, standard VB Open (for binary mode), and standard VB Put.

    If my results did not confuse me, I would be certain that my VB application and subsequent analysis was correct.

  4. #4
    old fart Frans C's Avatar
    Join Date
    Oct 1999
    Location
    the Netherlands
    Posts
    2,926
    I just posted this in the previous thread. Here is a link to IEEE specifications for single and double floating points.
    http://www.research.microsoft.com/~h...ieeefloat.html

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