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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

moving single into a double 1

Status
Not open for further replies.

autolab

Programmer
May 23, 2002
4
US
I am writing a Delphi app to read/write data files created by an old DOS app written in C ( Armor Systems - Advantage).
I am stuck trying to read a field used to figure mark-up percentages. They are storing this field in "Motorola model" which I assume means "Big Endian" order. Their instructions are to:
1. read the data as a long
2. swap the bytes to "Little Endian"
3. move into a double
4. multiply this by 0.0001

I assume Delphi's LongInt is the equivalent of C's Long. When I enter 30.00 in the DOS software, it stores $000493E0
in the file field. Converting this to Little Endian gives $E0930400. At this point I am lost. Can anyone help point me in the right direction?
 
Evidently the big/little endian swap has somehow been done for you. This may have to do with the way you're reading the value in.

$000493E0 is decimal 300,000. Multiply this by 0.0001, and you're left with 30.

You're right: Long is the same as LongInt. So it seems all you have to do is read the number, and then do the multiply by 0.0001 to scale it. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Doug Burbidge, thank you for your help. Here is what threw me off track and I still have not figured it out. If I do a hex file dump of the data file, the data is stored as $000493E0. If I read it into a LongInt variable(x) in Delphi and do a IntToHex(x), I get $E0930400. I solved the problem by creating a function to swap the bytes around. It seems the file has the data stored in Little Endian but the Delphi function IntToHex returns Big Endian. I would have expected Delphi to always return Little Endian since it is running on an Intel processor. Any thoughts on this?

Again thanls for your help.
Wes Grueninger
 
Hmm. Your number is stored big-endian in the file. When you do the read into your LongInt, I think Delphi is expecting to find a little-endian number (as you point out, this is the default for intel architecture). So I think it is here that the mistranslation occurs. -- Doug Burbidge mailto:dougburbidge@yahoo.com
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top