blindwig Posted June 27, 2005 Share Posted June 27, 2005 I wrote a set of UDFs for checking and setting the bits of a variable. I intended to do this to basically use a variable as an array of bits, but there are many other uses for such functions - I'll let you figure them out...The primary functions You'll find useful in this UDF are _FlagSet and _FlagClear, although you'll notice that you can use _FlagSet to clear a flag - I did this so that you can pass the results of a true/false expression directly through the flag, and not have to write an IF statement. For example:$Flags = _FlagSet($Flags, 3, $i > 0)will set bit 3 high if $i > 0, or low if not.There is also _FlagSetInPlace and _FlagClearInPlace, that use a ByRef instead of a return. That looks cleaner is some situations.Also notice the _FlagToString function, which is basically a value-to-binary-string function.And notice that i used a pre-determined set of flag masks, instead of calculating 2^x each and every time. I have actually done a performance check, but I'm assuming that this is faster.Enjoy! And as always, comments are welcome!MWR_Flag.au3 My UDF Threads:Pseudo-Hash: Binary Trees, Flat TablesFiles: Filter by Attribute, Tree List, Recursive Find, Recursive Folders Size, exported to XMLArrays: Nested, Pull Common Elements, Display 2dSystem: Expand Environment Strings, List Drives, List USB DrivesMisc: Multi-Layer Progress Bars, Binary FlagsStrings: Find Char(s) in String, Find String in SetOther UDF Threads I Participated:Base64 Conversions 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