A
Andy
Sigh... working on it for whole day and got no idea...
Basically I want to have a bitmask filtering function, I will throw in
3 parameters:
bitMaskValue - current bitmask value
filterValue - the value I want to see if its exist in "bitMaskValue"
BiggestValue - the maximum individual value can be exist
And I want it just to return true if the value exist, or false if not
So for example, I have 7 as "bitMaskValue", "filterValue" as 2 and
"BiggestValue" as 4... then it will return True... as 1 + 2 + 4 = 7
If I have 5 as "bitMaskValue", "filterValue" as 2 and "BiggestValue"
as 4... then it will return False... as 1 + 4 = 5... no "2"
I have come up the following be it just don't work
Private Function BitMaskFilter(ByVal bitMaskValue As Int32, ByVal
filterValue As Int32, ByVal BiggestValue As Int32) As Boolean
' Filter "filterValue" from "bitMaskValue" and return true if
value
' BiggestValue = biggest individual BitMask value
Dim filed As Boolean = False
While bitMaskValue > 1 And BiggestValue > 0
If bitMaskValue >= BiggestValue And BiggestValue <>
filterValue Then
bitMaskValue = bitMaskValue - BiggestValue
End If
If BiggestValue = filterValue Then
filed = True
End If
BiggestValue = BiggestValue / 2
End While
If filed Then
Return bitMaskValue = filterValue
Else
Return bitMaskValue = 0
End If
End Function
If I have the maximum possible value (in this case, 7) then it's ok...
if I have a bit missing in between the function will fail... I have
tried so many approach but I just can't think through it... any help
would be appericiated.
Thanks in advance.
Basically I want to have a bitmask filtering function, I will throw in
3 parameters:
bitMaskValue - current bitmask value
filterValue - the value I want to see if its exist in "bitMaskValue"
BiggestValue - the maximum individual value can be exist
And I want it just to return true if the value exist, or false if not
So for example, I have 7 as "bitMaskValue", "filterValue" as 2 and
"BiggestValue" as 4... then it will return True... as 1 + 2 + 4 = 7
If I have 5 as "bitMaskValue", "filterValue" as 2 and "BiggestValue"
as 4... then it will return False... as 1 + 4 = 5... no "2"
I have come up the following be it just don't work

Private Function BitMaskFilter(ByVal bitMaskValue As Int32, ByVal
filterValue As Int32, ByVal BiggestValue As Int32) As Boolean
' Filter "filterValue" from "bitMaskValue" and return true if
value
' BiggestValue = biggest individual BitMask value
Dim filed As Boolean = False
While bitMaskValue > 1 And BiggestValue > 0
If bitMaskValue >= BiggestValue And BiggestValue <>
filterValue Then
bitMaskValue = bitMaskValue - BiggestValue
End If
If BiggestValue = filterValue Then
filed = True
End If
BiggestValue = BiggestValue / 2
End While
If filed Then
Return bitMaskValue = filterValue
Else
Return bitMaskValue = 0
End If
End Function
If I have the maximum possible value (in this case, 7) then it's ok...
if I have a bit missing in between the function will fail... I have
tried so many approach but I just can't think through it... any help
would be appericiated.
Thanks in advance.