question

Avishek K avatar image
0 Likes"
Avishek K asked Phil BoBo answered

Data Hexadecimal Representation

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?

FlexSim 20.1.2
flexsim 20.1.2xml
5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

1 Answer

·
Phil BoBo avatar image
0 Likes"
Phil BoBo answered Phil BoBo edited

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.)

5 |100000

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.

Write an Answer

Hint: Notify or tag a user in this post by typing @username.

Up to 12 attachments (including images) can be used with a maximum of 23.8 MiB each and 47.7 MiB total.