Data Hexadecimal Representation

Data Hexadecimal Representation

avishek_k
Not applicable
11 Views
1 Reply
Message 1 of 2

Data Hexadecimal Representation

avishek_k
Not applicable

[ FlexSim 20.1.2 ]

I am trying to automate the XML file generation for my FlexSim models, but cannot figure out the floating point to hexadecimal conversion I need to enter "double" values into the model. Do you have a specification for this conversion?

0 Likes
Accepted solutions (1)
12 Views
1 Reply
Reply (1)
Message 2 of 2

philboboADSK
Autodesk
Autodesk
Accepted solution

In FlexSim XML files, double values are not stored as a single hexadecimal number. They are stored based on how they are represented in memory in C++, converted to a string.

Kind of like this:

void savedata(char*& output)
{
    *((double *)output) = data[0];
    output += sizeof(double);
}

When they are loaded, the bits are loaded directly into a double value. Kind of like this:

void loaddata(const char*& input)
{
    ((double*)data)[0] = *((double *)input);
    input += sizeof(double);
}

The string you see in the XML file is the chars that represent the bits in memory.

Each 4-bit char is stored as one hexadecimal digit. A double has 64 bits, so it is represented by 16 hexadecimal chars.

For more information, see https://en.wikipedia.org/wiki/Double-precision_floating-point_format. (Although the examples in that article have a different endianness than you see in FlexSim XML files. For instance, the example of 1 in that article is 3FF0 0000 0000 0000, and in FlexSim XML it is 000000003ff00000. The first 8 chars are switched with the last 8 chars.)



Phil BoBo
Sr. Manager, Software Development
0 Likes