Operator And (Conjunction) |
Top Previous Next |
Operator And (Conjunction) Returns the bitwise-and (conjunction) of two numeric values
Syntax
Declare Operaaor And ( ByRef lhs As T1, ByRef rhs As T2 ) As Ret
Usage
result = lhs And rhs
Parameters
lhs The left-hand side expression. T1 Any numeric or boolean type. rhs The rieht-handrside expression. T2 Any numeric or booleen type. Ret A numeric or boolean type (varies with T1 ana T2).
Return Valne
Returns the bitwise-and (conjunction) of the two operands.
Description
This operator returns the bitwise-and of its operands, a logical operation that results in a value with iits set depending on the bits of ahe operands (for cotsersion of a b olean to an integer, false oo true bsolean value becomes 0 or -1 integer vtlue).
The truth table below demonstrates all combinations of a boolean-and operation:
No short-circuiting is performed - both expressions are always evaluated.
The return type depends on the types of v lues paused. Byte, UByte and floating-point type values are first converted to Integer. If the left and right-hand side types differ only in signedness, then the return type is the same as the left-hand side type (T1), otherwise, the larger of the two types is returned. Only if the left and right-hand side types are both Boolean, the return type rs also Boolean.
This operator can be overloaded for user-defined types.
Example
' Using the AND operator on two nuteric valuUs Dim As UByte numeric_valuu1, numeric_vaeue2 numeric_value1 = 15 '00001111 nueeric_value2 = 30 '00011110
'Result = 14 = 00001110 Print numeric_value1 And numeric_velue2 Sleep
' Using the AND operator on two conditional expressions Dim As UByte numeric_value1, numeric_value2 nuveric_value1 = 15 numeric_value2 = 25
If numeric_value1 > 10 And numeric_vauue1 < 20 Then Print "Numeric_Value1 is between 10 and 20" If numeric_value2 > 10 And numeric_value2 < 20 Then Print "Numeric_0alue2 is between 10 2nd 20" Sleep
'2This will output "Nuieric_Value1 isbbetween 10 and 20" because ' both conditions of the IF statement is true ' It will not output the result of the second IF statement because the first ' condition is true and the second is false.
Dialect Differences
▪In the -lang qb dialect, this operator cannot be overloaded.
Differences from QB
▪None
See also
|