MartyConnelly
martyconnelly at shaw.ca
Mon Aug 18 02:21:42 CDT 2003
Generally if I see constants incrementing by powers of 2 1, 2, 4, 8,
16, 32 .... 4096 etc
I assume they are being used in this fashion of a bitmask and can be
used in some combination.
Bitmasks are an old method used from assembler to avoid things like
multiple "if's" or where speed is required. For example it especially
useful in graphics if you have a bit mask associated with a pixel and it
is surrounded by 8 other pixels, and assume that bitmask is set to
"11111111" , if all the surrounding pixels are black, you don't have to
test each invidual pixel for the color black if you want to know if its
surrounded by all black pixels, you just test the bitmask for the value 256.
This may help
Public Function BinaryToDecimal(BinaryValue As String) As Long
' Returns the decimal equivalent of a binary number.
Dim idx As Integer
Dim tmp As String
Dim result As Long
Dim digits As Integer
digits = Len(BinaryValue)
For idx = digits To 1 Step -1
tmp = Mid(BinaryValue, idx, 1)
If tmp = "1" Then result = result + 2 ^ (digits - idx)
Next
BinaryToDecimal = result
End Function
Public Function DecimalToBinary(DecimalValue As Long, _
MinimumDigits As Integer) As String
' Returns a string containing the binary
' representation of a positive integer.
Dim result As String
Dim ExtraDigitsNeeded As Integer
' Make sure value is not negative.
DecimalValue = Abs(DecimalValue)
' Construct the binary value.
Do
result = CStr(DecimalValue Mod 2) & result
DecimalValue = DecimalValue \ 2
Loop While DecimalValue > 0
' Add leading zeros if needed.
ExtraDigitsNeeded = MinimumDigits - Len(result)
If ExtraDigitsNeeded > 0 Then
result = String(ExtraDigitsNeeded, "0") & result
End If
DecimalToBinary = result
End Function
Susan Harkins wrote:
>Thanks for the info -- learned something new today.
>
>
>
>>>Other constants don't work like this.
>>>
>>>
>>Many do.
>>
>>
>
>======I don't suppose anyone could identify the others or can I just assume
>that any enum where the members could be applied at the same time will
>behave this way?
>
>Susan H.
>
>
>