Benny asked the same question, so a quick explanation for anyone else who comes across this thread and who is not binary-flag-aware.
It is common practice to store similar flags as bits (on or off) in a single datum.
Using an eight bit field as an example, you have eight possible flags. Their positions and values are:
Code:
76543210
--------
00000001 - 1
00000010 - 2
00000100 - 4
00001000 - 8
00010000 - 16
00100000 - 32
01000000 - 64
10000000 - 128
You can explicitly set the flags in the field just by adding the values together, so to set the flags at positions 1 and 6 you would use 2+64 = 66. However this also sets all the other flags to zero which may not be what you want.
If you use the bitwise OR which is "|" in KiXtart, then only the flags that you specify will be set - the other flags will be left unchanged.
You cannot simply add the flag values to the existing value. If you do this then (as Les says) the flag will "carry" to the next higher position. This is easy to see with an example.
Say you try to set flag 1 four times using addition. This is what would happen:
Code:
76543210
--------
00000000 - Start, add 2 (the value of flag 1)
00000010 - SUCCESS! flag #1 is set. Now add it again.
00000100 - Oh-oh! The flag is unset, and worse flag #2 is set.
00000110 - Success! We've set flag #1 again
00001000 - Oh-oh! Flag#1 is unset and so is flag #2, but now flag #3 is set!
As you can see, it's all turned into a horrible mess.
Even when you are setting bit-fields explicitly it is good programming practice to only use bitwise operators to manipulate them. Not only does this serve as a reminder of what you are changing, but it helps to avoid costly hard to find errors if the field use should later change.
To complete the story, you can safely use simple addition and subtraction to change bit settings, but only if you check the setting first:
Code:
; To set the flag:
If Not ($objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD)
$objUserFlags=$objUserFlags + $ADS_UF_DONT_EXPIRE_PASSWD
EndIf
; To clear a flag
If $objUserFlags & $ADS_UF_DONT_EXPIRE_PASSWD
$objUserFlags=$objUserFlags - $ADS_UF_DONT_EXPIRE_PASSWD
EndIf