WildByDesign Posted December 6 Posted December 6 I have two different PowerShell scripts that achieve the same thing. Either one can be used as an example. But essentially I need to create a function in AutoIt that does the same thing. The problem is that I don't even understand the math operations involved. I tried playing around with BitShift and BitAND for about an hour but I was completely unsuccessful. Script1: # example $packed = 2814749767106561 # decoding $major = $packed -shr 48 $minor = $packed -shr 32 -band 0xffff $build = $packed -shr 16 -band 0xffff $revision = $packed -band 0xffff "$major.$minor.$build.$revision" Script2: $exampleversion = "2814749767106561" $binexampleversion = [Convert]::ToString($exampleversion,2) $patch = [Convert]::ToInt32($binexampleversion.Substring($binexampleversion.Length-16),2) $build = [Convert]::ToInt32($binexampleversion.Substring($binexampleversion.Length-32, 16),2) $minor = [Convert]::ToInt32($binexampleversion.Substring($binexampleversion.Length-48, 16),2) $major = [Convert]::ToInt32($binexampleversion.Substring(0, $binexampleversion.Length -64 +16),2) "$major.$minor.$build.$patch" Both scripts take in the number 2814749767106561 and spits out a version string: 10.0.0.1 That initial number will vary, of course. It's just used as an example. If someone is able to help me create a function for AutoIt, my next step will be to create a loop to go through a column in an array or listview. I can do that part. But I really don't understand the math involved above to create the function in the first place. The function can be based off of either script because they both do the exact same thing. Thank you for your time. I appreciate it.
Solution TheXman Posted December 6 Solution Posted December 6 (edited) I would do something like this: #include <Constants.au3> MsgBox($MB_ICONINFORMATION, "Info", "Version = " & get_version_number(2814749767106561)) Func get_version_number($iVersion) Local $tUInt64 = DllStructCreate("uint64 value;"), _ $tVersion = DllStructCreate("word revision; word build; word minor; word major", DllStructGetPtr($tUInt64)) $tUInt64.value = $iVersion Return StringFormat('%i.%i.%i.%i', $tVersion.major, $tVersion.minor, $tVersion.build, $tVersion.revision) EndFunc Edited December 6 by TheXman CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Nine Posted December 6 Posted December 6 Your number is 64 bits. AutoIt Bit* functions are currently 32 bits. Look in my signature for bitwise x64 UDF. “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
pixelsearch Posted December 6 Posted December 6 Guys, could the script below fail in some cases ? Thanks Local $iPacked = 2814749767106561 Local $sPacked = Hex($iPacked, 16) ConsoleWrite($sPacked & @crlf) ; "000A000000000001" Local $aChunk[4] For $i = 0 To 3 $aChunk[$i] = Dec(StringMid($spacked, $i*4 + 1 , 4)) Next Local $sUnPacked = $aChunk[0] & "." & $aChunk[1] & "." & $aChunk[2] & "." & $aChunk[3] ConsoleWrite($sUnPacked & @crlf) ; "10.0.0.1"
WildByDesign Posted December 6 Author Posted December 6 (edited) What a great community! Thank you all for your help. Without a doubt, having multiple code snippets to play with really helps to understand how certain things work and opens up the mind for someone like myself who is still learning. I appreciate it. @TheXman and @pixelsearch Both of your examples worked in 100% of the use cases that I passed to them. Not a single failure and all matched up to the expected version strings. Performance was great as well. Now I just have to create the loop to swap (up to 32) version numbers in an array. So I will just have to see which example suits the functionality of the loop. I should be able to do this part by myself. @Nine You're right. That also explains why my results were coming out wrong even when I was sure that I had at least some of it done right. I tried with your UDF and sure enough, it did work. I can technically use your UDF and have a much smaller sized function in the end. The only thing that I am hesitant about is bundling the DLL with it. I could FileInstall it. But my goal is to have a single, portable executable for my app. I am still on the fence about it. Edited December 6 by WildByDesign spelling
TheXman Posted December 6 Posted December 6 (edited) @WildByDesign Just in case you need to generate a version number from the version string parts, I added a function that shows the inverse conversion. Although the inverse conversion may be obvious to me, it might not be so obvious to others how simple it is, especially for those who are not familiar with structs and how values are stored in memory. #include <Constants.au3> MsgBox($MB_ICONINFORMATION, "Info", _ "Version string = " & get_version_string(2814749767106561) & @CRLF & _ "Version number = " & get_version_number(10, 0, 0, 1) _ ) Func get_version_string($iVersion) Local $tVerNum = DllStructCreate("uint64 value;"), _ $tVersion = DllStructCreate("word revision; word build; word minor; word major", DllStructGetPtr($tVerNum)) ;Load integer into struct $tVerNum.value = $iVersion ;Return version string Return StringFormat('%i.%i.%i.%i', $tVersion.major, $tVersion.minor, $tVersion.build, $tVersion.revision) EndFunc Func get_version_number($iMajor, $iMinor = 0, $iBuild = 0, $iRevision = 0) Local $tVerNum = DllStructCreate("uint64 value;"), _ $tVersion = DllStructCreate("word revision; word build; word minor; word major", DllStructGetPtr($tVerNum)) ;Load version parts into struct $tVersion.major = $iMajor $tVersion.minor = $iMinor $tVersion.build = $iBuild $tVersion.revision = $iRevision ;Return version number Return $tVerNum.value EndFunc Edited December 9 by TheXman ioa747 1 CryptoNG UDF: Cryptography API: Next Gen jq UDF: Powerful and Flexible JSON Processor | jqPlayground: An Interactive JSON Processor Xml2Json UDF: Transform XML to JSON | HttpApi UDF: HTTP Server API | Roku Remote: Example Script About Me How To Ask Good Questions On Technical And Scientific Forums (Detailed) | How to Ask Good Technical Questions (Brief) "Any fool can know. The point is to understand." -Albert Einstein "If you think you're a big fish, it's probably because you only swim in small ponds." ~TheXman
Nine Posted December 6 Posted December 6 8 hours ago, WildByDesign said: I am hesitant about is bundling the DLL Don't be now. FYI, I just made a new version without DLL based on Intel ASM. “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
WildByDesign Posted December 6 Author Posted December 6 I just wanted to thank everyone again for helping. I learned a lot from this experience too. The loop ended up working great and I am able to convert all of the integers into version strings for the whole array column which gets fed into a listview shortly after. Cheers! 4 hours ago, TheXman said: Just in case you need to generate a version number from the version string parts, I added a function that shows the inverse conversion. Thank you so much. I can probably use the inverse conversion also.
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