Jump to content
Sign in to follow this  
CodeMaster Rapture

Trying to simplify some settings.

Recommended Posts

Hello all,

It is my understanding that bit shifting can be faster (and more memory efficient) than having an array of booleans. So, I'm curious how I can duplicate the following C++ code in Au3:

#define IS_SET(flag, bit)   ((flag) & (bit))
#define SET_BIT(var, bit)   ((var) |= (bit))
#define REMOVE_BIT(var, bit)    ((var) &= ~(bit))
#define TOGGLE_BIT(var, bit)    ((var) ^= (bit))

#define SPELL_HASTE     =   1
#define SPELL_SLEEP     =   2
#define SPELL_BLIND     =   4
#define SPELL_STRENGTH      =   8


int SpellsAffecting = 0;

if (IS_SET(SpellsAffecting,SPELL_HASTE))

//Or an easier method:

Since Au3 is designed in C++, do the same operators apply? (&,^,|,&=,|=,^=, and ~)

Just trying to eliminate an array of booleans for the sake of sanity and confusion. One concern I have is what would happen in the C++ code if I set the same bit more than once? Would the same thing happen in Au3 aswell?



Share this post

Link to post
Share on other sites

Ok, I've made some progress, just need some help on one function (or understanding of bitwise operation).

Func _IS_SET($bt_Bit,$bt_Value)
    Return BitAND($bt_Bit,$bt_Value)

Func _SET_BIT(ByRef $bt_Bit,$bt_Value)
    $bt_Bit = BitOR($bt_Bit,$bt_Value)

Func _TOGGLE_BIT(ByRef $bt_Bit,$bt_Value)
    $bt_Bit = BitXOR($bt_Bit,$bt_Value)

;Does not work:
Func _REMOVE_BIT(ByRef $bt_Bit,$bt_Value)
    $bt_Bit = BitAND($bt_Bit,$bt_Value)
oÝ÷ Ùh^¬y9Q!2(êv·¬º[ljëh×6
Global $My_Bits = 0

;All bits are set... so now lets try to remove bit 8...

;Mkay... odd, now $My_Bits == 8.... So everything was removed EXCEPT 8...

$My_Bits = 0

;Only 4 is set right now... let's try and remove 8 for the heck of it...

;Great, now $My_Bits == 0......

Any idea what I'm doing wrong?


Share this post

Link to post
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
Sign in to follow this  

  • Recently Browsing   0 members

    No registered users viewing this page.

  • Create New...