Representing float values in hex

This is a discussion on Representing float values in hex within the Tech Board forums, part of the Community Boards category; I need someone to explain this to me. I was looking at the disassembly of this: Code: void func (void) ...

  1. #1
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709

    Representing float values in hex

    I need someone to explain this to me. I was looking at the disassembly of this:

    Code:
    void func (void)
    {
            float   fl_one = 0.0f;
            float   fl_two = 0.0f;
            float   fl_ans = 0.0f;
    
            fl_one = 2.2f;
            fl_two = 3.5f;
            
            fl_ans = fl_one + fl_two;
    }
    The disassembly of the assignment is as follows:

    Code:
    mov         dword ptr [fl_one],400CCCCDh
    mov         dword ptr [fl_two],40600000h
    How the hell does 400CCCCDh represent 2.2? I replaced "fl_one = 2.2f;" with

    Code:
    mov fl_one, 400CCCCDh
    And it works so I assume the hex number isn't something to do with the compiler storing values (or something).

    Can someone explain / link to how floating point vals are represented in hex? I would prefer someone explaining it
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

  2. #2
    and the hat of wrongness Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    32,548
    1 sign bit
    8 bits of biased exponent
    23 bits of mantissa
    http://stevehollasch.com/cgindex/coding/ieeefloat.html

  3. #3
    Supermassive black hole cboard_member's Avatar
    Join Date
    Jul 2005
    Posts
    1,709
    Thanks for the link
    I did start to read about the IEEE standard on the art of assembly site, but his images seem to be buggered (corrupted maybe) and images really help... even simple tables.
    Good class architecture is not like a Swiss Army Knife; it should be more like a well balanced throwing knife.

    - Mike McShaffry

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Hex to float problem
    By supi in forum C Programming
    Replies: 1
    Last Post: 07-01-2008, 01:24 AM
  2. Replies: 8
    Last Post: 03-26-2007, 05:48 PM
  3. Repetition in do{}while
    By Beast() in forum C Programming
    Replies: 25
    Last Post: 06-16-2004, 10:47 PM
  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. Why does it work in Visual Studio and Not Borland
    By MonteMan in forum C++ Programming
    Replies: 14
    Last Post: 10-20-2002, 09:36 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21