Jump to content

UDFs: _Flag*


blindwig
 Share

Recommended Posts

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!

Link to comment
Share on other sites

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...