In VB, I'm going to have a set of flag constants that are powers of 2 (1,2,4,8,16,32,64, etc) so that my flag variable (a long integer) can have many combinations of those flags (using 'Or' to build the value and 'And' to read it)

Anyways, how can I take a number that's made up of 2 or more of these flags, and then find out which bits in the number are set to 1

Example..

VB Code:
  1. const flag1 = 2 '0000 0010
  2. const flag2 = 8 '0000 1000
  3. Dim L As Long
  4. Dim I As Integer
  5.    
  6. L = flag1 Or flag2 ' L is 0000 1010
  7.  
  8. If (L And flag1) = flag1 Then
  9.    
  10.     I = ' code to find which bit in flag1 is turned on (should return 2)
  11.    
  12.     Msgbox "The " & i & "nd bit is on"
  13.    
  14. End If
  15.  
  16. If (L And flag2) = flag2 Then
  17.    
  18.     I = ' code to find which bit in flag2 is turned on (should return 4)
  19.    
  20.     Msgbox "The " & i & "th bit is on"
  21.    
  22. End If

So basically, I need to know how to know which power of 2 a number is.