Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Hex editing a double-precision float 1

Status
Not open for further replies.

chpicker

Programmer
Apr 10, 2001
1,316
I have a file structure that includes 4 doubles. The doubles show up in the file, and I believe they translate as follows:
Code:
30 81 5B 77 F3 C8 57 C0: -95.1398600000
E2 71 51 2D 22 A4 46 40:  44.9848565000
DC 0E 0D 8B 51 83 57 C0: -94.0518520000
8B 33 86 39 41 E3 46 40:  46.0728645000
The numbers represent the bounding rectangle that encloses Stearns County, MN in latitude and longitude. The order of numbers is: X Min, Y Min, X Max, Y Max. The hex numbers are in the right order, and I believe I got the actual numbers in the right order, but I thought I would specify the file order in case I made a mistake.

Does anyone have any idea how this works? How do you convert the hex representation into the actual data?
 
The order in storage is simply reversed, which you can show as follows:

union
{
double d;
__int64 i;
} u1;

u1.i = 0xc057c8f3775b8130;
cout << u1.d;
:) Hope that this helped! :)
 
Thanks! I didn't end up using exactly what you have, but it showed me that C++ can simply convert the hex values straight to decimal by telling it to do it. I'm using the printf() function on the double value and having it output in hex format or float format depending on which way I want to go. Thanks again!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top