EddieBoy Posted October 23, 2017 Share Posted October 23, 2017 I've run into an issue with Hex( ). Basically, its returning a wonky 64bit value when asked to convert an integer well below the signed 32bit limit. If it makes a difference, my program pulls this value from an array and needs to convert it to hex before writing it to a txt file. The program scans a binary file for specific values, if it finds the value, enters it's location into an array, passes the array to this function which outputs the info to a text file. If I feed Hex() the same numbers directly, it works beautifully, so I'm not able to recreate this issue in a small code snippet. Hopefully a screen shot showing the problem will suffice. The $b variable is taken from an array (ie $b = $array[$i][0]). I've spent two days finding the source of this issue and looking for a solution with no luck. Any help is greatly appreciated! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted October 23, 2017 Moderators Share Posted October 23, 2017 EddieBoy, The fact Hex works correctly when fed the number directly indicates that there is some problem with the values you are extracting from your array. I suggest looking carefully at exactly what you are getting when reading the array values - for example: use the VarGetType function to check that the variable is the expected datatype; use StringToBinary to check for non-printing characters attached to the extracted value; etc. M23 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
EddieBoy Posted October 23, 2017 Author Share Posted October 23, 2017 (edited) Melba32 Thank you so much! I scoured the help file, yet somehow managed to miss VarGetType . The type is showing 'double' , which I would expect is the issue. I would be stretching it to call myself an intermediate programmer, but aren't doubles used for floating-point numbers, yet IsFloat () return False. The array number comes from a simple "For" loop, $count = 1... $count = $count+1 .... $count = $count * 4 ... $array[$i][0] = $count. Perhaps declaring the original variable type instead of leaving it to Autoit would help. I'll keep digging with this new info. Really appreciate the lead! UPDATE: using " Number($double,1) " fixed the issue (double to 32 bit integer conversion), but I'm still going to dig into why it was stored as a double so I can avoid the wasted conversion. A little research shows that a "double" does store 64 bits of floating point data, but isn't called "float" which exclusively stores 32bit floating point data. I expect that's why IsFloat returned False. Again, thanks much Melba! Edited October 23, 2017 by EddieBoy Link to comment Share on other sites More sharing options...
jchd Posted October 23, 2017 Share Posted October 23, 2017 Just a note: AutoIt doesn't use what used to be a "float" (vs. double) as a 32-bit FP value. All FP values are double. Read again the help under IsFloat() and IsInt() since they don't do what you seem to believe they do, whatever counter-intuitive it may sound. Use of Int(<value>) is simpler. This wonderful site allows debugging and testing regular expressions (many flavors available). An absolute must have in your bookmarks.Another excellent RegExp tutorial. Don't forget downloading your copy of up-to-date pcretest.exe and pcregrep.exe hereRegExp tutorial: enough to get startedPCRE v8.33 regexp documentation latest available release and currently implemented in AutoIt beta. SQLitespeed is another feature-rich premier SQLite manager (includes import/export). Well worth a try.SQLite Expert (freeware Personal Edition or payware Pro version) is a very useful SQLite database manager.An excellent eBook covering almost every aspect of SQLite3: a must-read for anyone doing serious work.SQL tutorial (covers "generic" SQL, but most of it applies to SQLite as well)A work-in-progress SQLite3 tutorial. Don't miss other LxyzTHW pages!SQLite official website with full documentation (may be newer than the SQLite library that comes standard with AutoIt) Link to comment Share on other sites More sharing options...
czardas Posted October 23, 2017 Share Posted October 23, 2017 (edited) @EddieBoy $count = 1... $count = $count+1 .... $count = $count * 4 does not convert $count, from Int-32/Int-64 to a double. Division and power operators always do convert the result to a double. Therefore $count must have been a double to start with. I'm not sure how much of this is intentional: there have been several developers involved in the history of AutoIt. It could also be that you stumbled on a hidden bug, but I think it's something in your code. Edited October 23, 2017 by czardas operator64 ArrayWorkshop Link to comment Share on other sites More sharing options...
EddieBoy Posted October 24, 2017 Author Share Posted October 24, 2017 Wow, thank you everyone for these insights. jchd: I was indeed misunderstand what IsFloat( ) and IsInt( ) did. Apparently they test the data in the variable rather that check the variable 'type'. So IsFloat will return false for floating point Type data, as long as that data is a whole number ie. IsFloat(1.00) = False. That explains one of the reasons I had trouble tracking this bug down . czardas : I went back and checked the function. My example left one 'addition' element out of the equation, and that element seems to be the issue: it's a hex value stored as "string" type that is read from a input field as such: $variable = "0x" & GuiCtrlRead($InputField) All the other variables involved test as Int32 but when the hex value in "string" format is included, Autoit outputs the product as a "double" type. At least now I can convert the string to a decimal as soon as it's read from the GUI. If I'm thinking right, that should at least shrink the array's size in RAM. Thanks everyone, the info here will be quite helpful! czardas 1 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