One thing to consider, Bitwise.BitAnd is about 10x slower than plain “And” so if you are doing high performance code, it’s to be avoided. (But if you are doing high performance code, you shouldn’t be using Val() either… )
I am sorry, I may be mistaken, but from what I understand reading the LR, regular And does not seem suited to perform anything but a boolean evaluation with a boolean result. As far as I see, Tim needs a bitwise And that gives a numeric result to compare to &H4000.
dim foo as integer = &hF000
dim bar as integer = &hFF00
dim foobar as integer = foo AND bar
MsgBox hex(foobar)
Shows “F000”
[Edit] My LR clearly says it does bitwise operations, e.g. “And: Used to perform a logical comparison of two boolean expressions and a bitwise And comparison of two integer expressions.”
[quote=197473:@Michael Diehr]The LR is wrong if that’s what it says:
dim foo as integer = &hF000
dim bar as integer = &hFF00
dim foobar as integer = foo AND bar
MsgBox hex(foobar)
Shows “F000”
[Edit] My LR clearly says it does bitwise operations, e.g. “And: Used to perform a logical comparison of two boolean expressions and a bitwise And comparison of two integer expressions.”[/quote]
Alright. Thank you. Casting did not work, but your code is probably the solution. Instead of using Val and a literal directly, using variables makes it work :
[code] dim foo as integer = Val("&hD31C")
dim bar as integer = &h4000
if (foo AND bar) = &H4000 then
MsgBox “True”
end if[/code]
Okay, so the obviousness of this one didn’t escape me, it’s truly odd… I had already tried integer casting and when that also didn’t work, I went and played Diablo III :D.
You played Diablo III and feel much better? I had a hardcore character with over 172 hours vested, and died from walking into a situation while my chat window was focused (was in town typing to a friend, and clicked back on the portal to confront a rift guardian). All the key-presses went to the chat field instead of the action bar, in the 3 seconds it took to kill me. By the time I figured out what had happened… too late. I was not feeling better… and actually took to Xojo for the escape. I haven’t touched the game since (that was season one).