Bitwise Enumeration?
-
Hi all, Not sure if my subject is correct in describing what I want to do. I have an integer variable (iOptions) where each bit represents an On/Off Flag: 0 = all off 1 = flag1 2 = flag2 4 = flag3 8 = flag4 ....... and so on Of course this integer variable could equal to 7 (flag1+flag2+flag3 are On) or anywhere in between. How do I write a bitwise if statement to check if anyone flag is On?
if iFlag1 ?? iOptions then ' **What goes here instead of ??** ... else if iFlag2 ?? iOptions then ... end if
Thanks, Karen Nooobie to OOP and VB.Net 2005 -
Hi all, Not sure if my subject is correct in describing what I want to do. I have an integer variable (iOptions) where each bit represents an On/Off Flag: 0 = all off 1 = flag1 2 = flag2 4 = flag3 8 = flag4 ....... and so on Of course this integer variable could equal to 7 (flag1+flag2+flag3 are On) or anywhere in between. How do I write a bitwise if statement to check if anyone flag is On?
if iFlag1 ?? iOptions then ' **What goes here instead of ??** ... else if iFlag2 ?? iOptions then ... end if
Thanks, Karen Nooobie to OOP and VB.Net 2005If I got it correctly you want to check a specific bit if is on or off. Several ways. Tha basic one is to OR the integer with the bit mask and check if the result is (or not) 0. if (a OR 1) = 0 then bit0_notset else bit0_set if (a OR 2) = 0 then bit1_notset else bit1_set if (a OR 4) = 0 ... Briga
-
If I got it correctly you want to check a specific bit if is on or off. Several ways. Tha basic one is to OR the integer with the bit mask and check if the result is (or not) 0. if (a OR 1) = 0 then bit0_notset else bit0_set if (a OR 2) = 0 then bit1_notset else bit1_set if (a OR 4) = 0 ... Briga
-
-