Hello.Help me to understand.
Using Immediate Window of IDE Microsoft Visual Basic,calculate values of following
expressions on the base bit-by-bit operator Or.
In Immediate Window I'm writting following
?2 or 3 [Enter]
3
Result is 3. Is it so?
Thanks.

Dani AI

Generated

gave the right, brief explanation: Or on numeric values works bit-by-bit. Below are a few practical points and examples that clarify behavior you will see in the Immediate Window and avoid common surprises.

Example expressions you can try in the Immediate Window:

' Immediate Window (Visual Basic)
? 4 Or 1        ' 4 = 100b, 1 = 001b  -> 5
? 6 Or 3        ' 110b OR 011b       -> 7
? True Or False ' logical OR for Booleans -> True
? 0 Or -1       ' -1 is all bits set in two's complement -> -1

Notes and cautions:

  • Or is bitwise for numeric types and logical for Boolean types. Mixing booleans and numbers causes type coercion: a Boolean True becomes an integer with all bits set (commonly -1) when converted, which can give unintuitive numeric results.
  • In VB.NET, if you mean short-circuit logical OR for Boolean expressions, use OrElse (it skips evaluating the right-hand operand when the left is True). See the docs for details: Or operator (Visual Basic) and .
  • If results look wrong, check operand types with TypeName() or cast explicitly (for example, use CInt/CBool) so operations happen in the type you expect.

If the Immediate Window output still seems odd, post the exact expression and the types involved. Also, is right to suggest marking the thread solved once the behavior is clear.

Recommended Answers

All 3 Replies

To understand this, you need to go back to basics. "OR" is a bitwise operation. The binary for 2 is X10, 3 is X11. ORing the two gives X11 which is 3.

Hoppy

Now I am assured.Thank you.

You should mark the thread as "Solved".

Hoppy

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.