Reverse Bitwise Operations

J

James Arnold

Say I have an enumeration of modifiers for a hotkey (which
conveniently I do!):

Private Enum HotkeyModifier
None = 0
Alt = 1
Ctrl = 2
Shift = 4
Win = 8
End Enum

Using this I can work out the modifier for Ctrl and Alt being pushed
(1 + 2). However, if I was given a value (e.g. 7), how would I extract
the individual modifiers used?

i.e.
7 -> Alt + Ctrl + Shift
5 -> Alt + Shift

....etc. Thanks again!
 
H

Herfried K. Wagner [MVP]

James Arnold said:
Say I have an enumeration of modifiers for a hotkey (which
conveniently I do!):

Private Enum HotkeyModifier
None = 0
Alt = 1
Ctrl = 2
Shift = 4
Win = 8
End Enum

Using this I can work out the modifier for Ctrl and Alt being pushed
(1 + 2). However, if I was given a value (e.g. 7), how would I extract
the individual modifiers used?

\\\
If CBool(Value And HotkeyModifier.Alt) Then
...
End If
///
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top