Jump to content



Photo

UDFs: _Flag*


  • Please log in to reply
No replies to this topic

#1 blindwig

blindwig

    Universalist

  • Active Members
  • PipPipPipPipPipPip
  • 772 posts

Posted 27 June 2005 - 07:08 AM

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!

Attached Files












0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users