Yincognito Posted November 28, 2023 Share Posted November 28, 2023 Simple question: I'm extracting all individual states from a WinGetState() function as base 2 numbers concatenated into a string using space separators, and I was wondering if there's a shorter way of doing something like this (maybe a ? after the function, enclosing it between brackets to force it into a 0 or 1 value, or something along those lines) - the reason is not important, I'm just curious: BitAND($Sta, 4) / 4 Link to comment Share on other sites More sharing options...
Andreik Posted November 28, 2023 Share Posted November 28, 2023 I wonder if anyone have any clue about what are you asking. So you have a string with all possible states returned by WinGetState() as base 2 numbers that are concatenated into a string using space separator between the states. $Sta = '1 10 100 1000 10000 100000' I assume something like this. Now what? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Solution Nine Posted November 28, 2023 Solution Share Posted November 28, 2023 ntdll.dll has numerous functions to convert (u)int to string (and vice versa) . Example : DllCall("ntdll.dll", "str:cdecl", "_ui64toa", "uint64", $integer, "str", "", "int", $base) by using a $base = 2, you get a binary string of the $integer Yincognito 1 “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...
Yincognito Posted November 28, 2023 Author Share Posted November 28, 2023 6 hours ago, Andreik said: I wonder if anyone have any clue about what are you asking. So you have a string with all possible states returned by WinGetState() as base 2 numbers that are concatenated into a string using space separator between the states. $Sta = '1 10 100 1000 10000 100000' I assume something like this. Now what? My bad, I thought I was clear enough in my post (I did say "all individual states" and not "all possible states", after all) - no need to be confrontational about it. Since you asked though, I have this (where $wHan is a window handle): $wSta = WinGetState($wHan) $wBit = BitAND($wSta, 1) / 1 & " " & BitAND($wSta, 2) / 2 & " " & BitAND($wSta, 4) / 4 & " " & BitAND($wSta, 8) / 8 & " " & BitAND($wSta, 16) / 16 & " " & BitAND($wSta, 32) / 32 And I was simply looking for a shorter, preferably AutoIt built-in function that would make converting the output of WinGetState() into a base 2 number or string that I could manipulate further by adding the space separators and reversing the bit order according to my needs, that's all. Link to comment Share on other sites More sharing options...
Nine Posted November 28, 2023 Share Posted November 28, 2023 This is what I am using to convert uint to bin string with spaces : Func UIntToBinary($nUInt) Local $sBin = DllCall("ntdll.dll", "str:cdecl", "_ui64toa", "uint64", $nUInt, "str", "", "int", 2)[0] Local $iLen = Ceiling(StringLen($sBin) / 4) * 4 $sBin = _StringRepeat("0", $iLen - StringLen($sBin)) & $sBin Return StringRegExpReplace($sBin, "(.{4})", "\1 ") EndFunc “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...
Yincognito Posted November 28, 2023 Author Share Posted November 28, 2023 (edited) 6 hours ago, Nine said: ntdll.dll has numerous functions to convert (u)int to string (and vice versa) . Example : DllCall("ntdll.dll", "str:cdecl", "_ui64toa", "uint64", $integer, "str", "", "int", $base) by using a $base = 2, you get a binary string of the $integer Many thanks, it looks like just what I need: $wBit = StringRegExpReplace(StringReverse(StringFormat("%06d", DllCall("ntdll.dll", "str:cdecl", "_ui64toa", "int64", WinGetState($wHan), "str", "", "int", 2)[0])), "(.)(?!$)", "\1 ") By the way, is there any difference in terms of performance if I first do ($wHan is a window handle): $wSta = WinGetState($wHan) before using $wSta in the $wBit assignment? Besides clarity, better debugging and so on, that is. It's a pity though that AutoIt has all those many binary functions and not a single one that does base conversion (apart from UDFs), e.g. like ToBase(value, base, positions) - and I looked quite a bit on the forums before posting this question. EDIT: Just saw your reply. Yep, that's a similar approach to what I've ended up with. It does its job, it fits one line, so the "no clutter / scrollbars" objective is achieved for my code. Edited November 28, 2023 by Yincognito Corrected typo. 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