Sideway
output.to from Sideway
Draft for Information Only

Content

VB.NET Logical/Bitwise Operators
  And Operator
  Syntax
  Parts
  Remarks
  Data Types
  See also
  Not Operator
  Syntax
  Parts
  Remarks
  Data Types
  Overloading
  See also
  Or Operator
  Syntax
  Parts
  Remarks
  Data Types
  Overloading
  See also
  Xor Operator
  Syntax
  Parts
  Remarks
  Data Types
  Overloading
  See also
  AndAlso Operator
  Syntax
  Parts
  Remarks
  Data Types
  Overloading
  See also
  OrElse Operator
  Syntax
  Parts
  Remarks
  Data Types
  Overloading
  See also
  IsFalse Operator
  See also
  IsTrue Operator
  Compiler Use of IsTrue
  See also
  Source/Reference

VB.NET Logical/Bitwise Operators

The supporting VB.NET Logical/Bitwise Operators are And, Not, Or, Xor, AndAlso, OrElse, IsFalse, IsTrue.

And Operator

Performs a logical conjunction on two Boolean expressions, or a bitwise conjunction on two numeric expressions.

Syntax

result = expression1 And expression2  

Parts

result: Required. Any Boolean or numeric expression. For Boolean comparison, result is the logical conjunction of two Boolean values. For bitwise operations, result is a numeric value representing the bitwise conjunction of two numeric bit patterns.

expression1" Required. Any Boolean or numeric expression.

expression2: Required. Any Boolean or numeric expression.

Remarks

For Boolean comparison, result is True if and only if both expression1 and expression2 evaluate to True. The following table illustrates how result is determined.

If expression1 is And expression2 is The value of result is
True True True
True False False
False True False
False False False

Note

In a Boolean comparison, the And operator always evaluates both expressions, which could include making procedure calls. The AndAlso Operator performs short-circuiting, which means that if expression1 is False, then expression2 is not evaluated.

When applied to numeric values, the And operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table.

If bit in expression1 is And bit in expression2 is The bit in result is
1 1 1
1 0 0
0 1 0
0 0 0

Note

Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate results.

Data Types

If the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation.

For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results.

Note

The And operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

Not Operator

Performs logical negation on a Boolean expression, or bitwise negation on a numeric expression.

Syntax

result = Not expression  

Parts

result: Required. Any Boolean or numeric expression.

expression: Required. Any Boolean or numeric expression.

Remarks

For Boolean expressions, the following table illustrates how result is determined.

If expression is The value of result is
True False
False True

For numeric expressions, the Not operator inverts the bit values of any numeric expression and sets the corresponding bit in result according to the following table.

If bit in expression is The bit in result is
1 0
0 1

Note

Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution.

Data Types

For a Boolean negation, the data type of the result is Boolean. For a bitwise negation, the result data type is the same as that of expression. However, if expression is Decimal, the result is Long.

Overloading

The Not operator can be overloaded, which means that a class or structure can redefine its behavior when its operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

Or Operator

Performs a logical disjunction on two Boolean expressions, or a bitwise disjunction on two numeric expressions.

Syntax

result = expression1 Or expression2  

Parts

result: Required. Any Boolean or numeric expression. For Boolean comparison, result is the inclusive logical disjunction of two Boolean values. For bitwise operations, result is a numeric value representing the inclusive bitwise disjunction of two numeric bit patterns.

expression1: Required. Any Boolean or numeric expression.

expression2: Required. Any Boolean or numeric expression.

Remarks

For Boolean comparison, result is False if and only if both expression1 and expression2 evaluate to False. The following table illustrates how result is determined.

If expression1 is And expression2 is The value of result is
True True True
True False True
False True True
False False False

Note

In a Boolean comparison, the Or operator always evaluates both expressions, which could include making procedure calls. The OrElse Operator performs short-circuiting, which means that if expression1 is True, then expression2 is not evaluated.

For bitwise operations, the Or operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table.

If bit in expression1 is And bit in expression2 is The bit in result is
1 1 1
1 0 1
0 1 1
0 0 0

Note

Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution.

Data Types

If the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation.

For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results.

Overloading

The Or operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

Xor Operator

Performs a logical exclusion on two Boolean expressions, or a bitwise exclusion on two numeric expressions.

Syntax

result = expression1 Xor expression2  

Parts

result
Required. Any Boolean or numeric variable. For Boolean comparison, result is the logical exclusion (exclusive logical disjunction) of two Boolean values. For bitwise operations, result is a numeric value that represents the bitwise exclusion (exclusive bitwise disjunction) of two numeric bit patterns.

expression1: Required. Any Boolean or numeric expression.

expression2: Required. Any Boolean or numeric expression.

Remarks

For Boolean comparison, result is True if and only if exactly one of expression1 and expression2 evaluates to True. That is, if and only if expression1 and expression2 evaluate to opposite Boolean values. The following table illustrates how result is determined.

If expression1 is And expression2 is The value of result is
True True False
True False True
False True True
False False False

Note

In a Boolean comparison, the Xor operator always evaluates both expressions, which could include making procedure calls. There is no short-circuiting counterpart to Xor, because the result always depends on both operands. For short-circuiting logical operators, see AndAlso Operator and OrElse Operator.

For bitwise operations, the Xor operator performs a bitwise comparison of identically positioned bits in two numeric expressions and sets the corresponding bit in result according to the following table.

If bit in expression1 is And bit in expression2 is The bit in result is
1 1 0
1 0 1
0 1 1
0 0 0

Note

Since the logical and bitwise operators have a lower precedence than other arithmetic and relational operators, any bitwise operations should be enclosed in parentheses to ensure accurate execution.

For example, 5 Xor 3 is 6. To see why this is so, convert 5 and 3 to their binary representations, 101 and 011. Then use the previous table to determine that 101 Xor 011 is 110, which is the binary representation of the decimal number 6.

Data Types

If the operands consist of one Boolean expression and one numeric expression, Visual Basic converts the Boolean expression to a numeric value (–1 for True and 0 for False) and performs a bitwise operation.

For a Boolean comparison, the data type of the result is Boolean. For a bitwise comparison, the result data type is a numeric type appropriate for the data types of expression1 and expression2. See the "Relational and Bitwise Comparisons" table in Data Types of Operator Results.

Overloading

The Xor operator can be overloaded, which means that a class or structure can redefine its behavior when an operand has the type of that class or structure. If your code uses this operator on such a class or structure, make sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

AndAlso Operator

Performs short-circuiting logical conjunction on two expressions.

Syntax

VB
result = expression1 AndAlso expression2  

Parts

result: Required. Any Boolean expression. The result is the Boolean result of comparison of the two expressions.

expression1: Required. Any Boolean expression.

expression2: Required. Any Boolean expression.

Remarks

A logical operation is said to be short-circuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result. Short-circuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls.

If both expressions evaluate to True, result is True. The following table illustrates how result is determined.

If expression1 is And expression2 is The value of result is
True True True
True False False
False (not evaluated) False

Data Types

The AndAlso operator is defined only for the Boolean Data Type. Visual Basic converts each operand as necessary to Boolean before evaluating the expression. If you assign the result to a numeric type, Visual Basic converts it from Boolean to that type such that False becomes 0 and True becomes -1. For more information, see Boolean Type Conversions

Overloading

The And Operator and the IsFalse Operator can be overloaded, which means that a class or structure can redefine their behavior when an operand has the type of that class or structure. Overloading the And and IsFalse operators affects the behavior of the AndAlso operator. If your code uses AndAlso on a class or structure that overloads And and IsFalse, be sure you understand their redefined behavior. For more information, see Operator Procedures.

See also

OrElse Operator

Performs short-circuiting inclusive logical disjunction on two expressions.

Syntax

result = expression1 OrElse expression2  

Parts

result: Required. Any Boolean expression.

expression1: Required. Any Boolean expression.

expression2: Required. Any Boolean expression.

Remarks

A logical operation is said to be short-circuiting if the compiled code can bypass the evaluation of one expression depending on the result of another expression. If the result of the first expression evaluated determines the final result of the operation, there is no need to evaluate the second expression, because it cannot change the final result. Short-circuiting can improve performance if the bypassed expression is complex, or if it involves procedure calls.

If either or both expressions evaluate to True, result is True. The following table illustrates how result is determined.

If expression1 is And expression2 is The value of result is
True (not evaluated) True
False True True
False False False

Data Types

The OrElse operator is defined only for the Boolean Data Type. Visual Basic converts each operand as necessary to Boolean before evaluating the expression. If you assign the result to a numeric type, Visual Basic converts it from Boolean to that type such that False becomes 0 and True becomes -1. For more information, see Boolean Type Conversions

Overloading

The Or Operator and the IsTrue Operator can be overloaded, which means that a class or structure can redefine their behavior when an operand has the type of that class or structure. Overloading the Or and IsTrue operators affects the behavior of the OrElse operator. If your code uses OrElse on a class or structure that overloads Or and IsTrue, be sure you understand their redefined behavior. For more information, see Operator Procedures.

See also

IsFalse Operator

Determines whether an expression is False.

You cannot call IsFalse explicitly in your code, but the Visual Basic compiler can use it to generate code from AndAlso clauses. If you define a class or structure and then use a variable of that type in an AndAlso clause, you must define IsFalse on that class or structure.

The compiler considers the IsFalse and IsTrue operators as a matched pair. This means that if you define one of them, you must also define the other one.

Note

The IsFalse operator can be overloaded, which means that a class or structure can redefine its behavior when its operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

IsTrue Operator

Determines whether an expression is True.

You cannot call IsTrue explicitly in your code, but the Visual Basic compiler can use it to generate code from OrElse clauses. If you define a class or structure and then use a variable of that type in an OrElse clause, you must define IsTrue on that class or structure.

The compiler considers the IsTrue and IsFalse operators as a matched pair. This means that if you define one of them, you must also define the other one.

Compiler Use of IsTrue

When you have defined a class or structure, you can use a variable of that type in a For, If, Else If, or While statement, or in a When clause. If you do this, the compiler requires an operator that converts your type into a Boolean value so it can test a condition. It searches for a suitable operator in the following order:

  1. A widening conversion operator from your class or structure to Boolean.

  2. A widening conversion operator from your class or structure to Boolean?.

  3. The IsTrue operator on your class or structure.

  4. A narrowing conversion to Boolean? that does not involve a conversion from Boolean to Boolean?.

  5. A narrowing conversion operator from your class or structure to Boolean.

If you have not defined any conversion to Boolean or an IsTrue operator, the compiler signals an error.

Note

The IsTrue operator can be overloaded, which means that a class or structure can redefine its behavior when its operand has the type of that class or structure. If your code uses this operator on such a class or structure, be sure you understand its redefined behavior. For more information, see Operator Procedures.

See also

Source/Reference


©sideway

ID: 200800003 Last Updated: 3/8/2020 Revision: 0 Ref:

close

References

  1. Active Server Pages,  , http://msdn.microsoft.com/en-us/library/aa286483.aspx
  2. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929%28v=vs.90%29.aspx
  3. ASP Best Practices,  , http://technet.microsoft.com/en-us/library/cc939157.aspx
  4. ASP Built-in Objects,  , http://msdn.microsoft.com/en-us/library/ie/ms524716(v=vs.90).aspx
  5. Response Object,  , http://msdn.microsoft.com/en-us/library/ms525405(v=vs.90).aspx
  6. Request Object,  , http://msdn.microsoft.com/en-us/library/ms524948(v=vs.90).aspx
  7. Server Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525541(v=vs.90).aspx
  8. Application Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525360(v=vs.90).aspx
  9. Session Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms524319(8v=vs.90).aspx
  10. ASPError Object,  , http://msdn.microsoft.com/en-us/library/ms524942(v=vs.90).aspx
  11. ObjectContext Object (IIS),  , http://msdn.microsoft.com/en-us/library/ms525667(v=vs.90).aspx
  12. Debugging Global.asa Files,  , http://msdn.microsoft.com/en-us/library/aa291249(v=vs.71).aspx
  13. How to: Debug Global.asa files,  , http://msdn.microsoft.com/en-us/library/ms241868(v=vs.80).aspx
  14. Calling COM Components from ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524620(v=VS.90).aspx
  15. IIS ASP Scripting Reference,  , http://msdn.microsoft.com/en-us/library/ms524664(v=vs.90).aspx
  16. ASP Keywords,  , http://msdn.microsoft.com/en-us/library/ms524672(v=vs.90).aspx
  17. Creating Simple ASP Pages,  , http://msdn.microsoft.com/en-us/library/ms524741(v=vs.90).aspx
  18. Including Files in ASP Applications,  , http://msdn.microsoft.com/en-us/library/ms524876(v=vs.90).aspx
  19. ASP Overview,  , http://msdn.microsoft.com/en-us/library/ms524929(v=vs.90).aspx
  20. FileSystemObject Object,  , http://msdn.microsoft.com/en-us/library/z9ty6h50(v=vs.84).aspx
  21. http://msdn.microsoft.com/en-us/library/windows/desktop/ms675944(v=vs.85).aspx,  , ADO Object Model
  22. ADO Fundamentals,  , http://msdn.microsoft.com/en-us/library/windows/desktop/ms680928(v=vs.85).aspx
close
IMAGE

Home 5

Business

Management

HBR 3

Information

Recreation

Hobbies 8

Culture

Chinese 1097

English 337

Reference 67

Computer

Hardware 149

Software

Application 198

Digitization 25

Latex 7

Manim 115

Numeric 19

Programming

Web 283

Unicode 494

HTML 65

CSS 58

ASP.NET 149

OS 389

DeskTop 7

Python 19

Knowledge

Mathematics

Formulas 8

Algebra 25

Number Theory 206

Trigonometry 18

Geometry 21

Calculus 67

Complex Analysis 21

Engineering

Tables 8

Mechanical

Mechanics 1

Rigid Bodies

Statics 92

Dynamics 37

Fluid 5

Fluid Kinematics 5

Control

Process Control 1

Acoustics 19

FiniteElement 2

Physics

Electric 27

Biology 1

Geography 1


Copyright © 2000-2020 Sideway . All rights reserved Disclaimers last modified on 06 September 2019