BryanWall Posted January 11 Share Posted January 11 To start, my recollection of Hex is bare bones. As in just about only recalling how to convert dec to hex type of bare bones. The problem: I have two things that are supposed to be equal. Namely a .txt file and a blob of Hex values in a database. I have documentation for which bytes are supposed to represent which columns in the txt file. The inputs: $HexTime = "036fa5ba" $HexLong = "c057119da597d49d" $HexRSL = "c288c7ae" $Time = 57648570 $Long = -92.275247 $RSL = -68.39 Goal: I need to be able to go both ways. What I have: Best I can tell everything is in "big endian". $HexTime = "036fa5ba" $HexLong = "0xc057119da597d49d" $HexRSL = "0xc288c7ae" $Time=57648570 $Long=-92.275247 $RSL=-68.39 ConsoleWrite("Time:" & Dec(($HexTime)) & @CRLF) ConsoleWrite("lng:" & _WinAPI_IntToFloat(($HexLong)) & @CRLF) ConsoleWrite("RSL:" & _WinAPI_IntToFloat(($HexRSL)) & @CRLF) ConsoleWrite("Time:" & Hex(($Time)) & @CRLF) ConsoleWrite("lng:" & Hex(_WinAPI_FloatToInt(($Long))) & @CRLF) ConsoleWrite("RSL:" & Hex(_WinAPI_FloatToInt(($RSL))) & @CRLF) The 4 byte time and RSL work just fine. However, the ones for the longitude doesn't work, presumably because it is 8 byte or double, not float. Time:57648570 lng:-2.63383968506439e-16 RSL:-68.3899993896484 Time:036FA5BA lng:C2B88CED RSL:C288C7AE I have tried various other things, like this: ; Set up the source and destination structures $src = DllStructCreate("byte;byte;byte;byte;byte;byte;byte;byte") $psrc = DllStructGetPtr($src) $dest = DllStructCreate("DOUBLE") $pdest = DllStructGetPtr($dest) $HexLong = "c057119da597d49d" $byte1 = StringMid($HexLong,1,2) $byte2 = StringMid($HexLong,3,2) $byte3 = StringMid($HexLong,5,2) $byte4 = StringMid($HexLong,7,2) $byte5 = StringMid($HexLong,9,2) $byte6 = StringMid($HexLong,11,2) $byte7 = StringMid($HexLong,13,2) $byte8 = StringMid($HexLong,15,2) ; Put the raw byte data into the source DllStructSetData($src, 1, $byte1) DllStructSetData($src, 2, $byte2) DllStructSetData($src, 3, $byte3) DllStructSetData($src, 4, $byte4) DllStructSetData($src, 5, $byte5) DllStructSetData($src, 6, $byte6) DllStructSetData($src, 7, $byte7) DllStructSetData($src, 8, $byte8) ; Perform the "conversion" _MemMoveMemory($psrc, $pdest, 8) ConsoleWrite(DllStructGetData($dest, 1) & @CRLF) But it outputs "2.53979544568635e-265" for this version. I've tried other versions but can't get it to work. This was adapted from Please ignore the ugly hardcode. I'll convert it to a for loop if it ends up that route. Link to comment Share on other sites More sharing options...
Solution Nine Posted January 11 Solution Share Posted January 11 Try this instead : $HexLong = 0xc057119da597d49d $Long=-92.275247 $tUint = DllStructCreate("int64 int") $tFloat = DllStructCreate("double flt", DllStructGetPtr($tUint)) $tUint.int = $HexLong ConsoleWrite($tUint.int & @CRLF) ConsoleWrite($tFloat.flt & @CRLF) $tUint.int = 0 ConsoleWrite($tUint.int & @CRLF) ConsoleWrite($tFloat.flt & @CRLF) $tFloat.flt = $Long ConsoleWrite($tUint.int & @CRLF) ConsoleWrite($tFloat.flt & @CRLF) ConsoleWrite(Hex($tUint.int, 16)& @CRLF) Musashi and 636C65616E 2 “They did not know it was impossible, so they did it” ― Mark Twain Spoiler Block all input without UAC Save/Retrieve Images to/from Text Monitor Management (VCP commands) Tool to search in text (au3) files Date Range Picker Virtual Desktop Manager Sudoku Game 2020 Overlapped Named Pipe IPC HotString 2.0 - Hot keys with string x64 Bitwise Operations Multi-keyboards HotKeySet Recursive Array Display Fast and simple WCD IPC Multiple Folders Selector Printer Manager GIF Animation (cached) Screen Scraping Multi-Threading Made Easy Link to comment Share on other sites More sharing options...
BryanWall Posted January 12 Author Share Posted January 12 That works, thank you. Apologies for the late reply. Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now