Topic: DMD0199

Help File Version: 2.10.0.636

Math Logical AND Operator


The Math Logical AND operator ( && ) indicates whether both operands are TRUE. A discrete operand is considered TRUE if it is ON; a numeric operand is considered TRUE if its value is non-zero.

 

The operands can be any mix of signed integers, unsigned integers, real (floating point) numbers or discrete values. They can be any numeric or discrete memory location, or any numeric or discrete structure member.

 

Traditional math precedence rules are used to solve the math expression. The use of parentheses to remove any ambiguity in the processing order is encouraged.

 

Refer to the examples below:

 

Signed Integers: assume D1 = 0 and D2 = 1 and X0 = ON and X1 = OFF

 

C0 = X0 && X1

C0 = ON && OFF

C0 = TRUE && FALSE
C0 = OFF

 

Both operands are discrete memory locations.

 

The result is placed in a discrete memory location.

 

C0 = (X0 && X1) && D1

 

C0 = (ON && OFF) && (0)

C0 = (TRUE && FALSE) && FALSE)
C0 = FALSE && FALSE

C0 = OFF

 

Two operands are discrete memory locations, the third is an integer memory location.

 

The result is placed in a discrete memory location.

 

 

D0 = X0 && D2

 

D0 = ON && 1

D0 = TRUE && TRUE
D0 = 1

 

One operand is a discrete memory location, the other is an integer memory location.

 

The result is placed in an integer memory location.

 

 

Numeric Structure Members: X0 = ON and Timer T0.Done = ON

 

C0 = X0 && T0.Done

 

C0 = ON && ON

C0 = TRUE && TRUE

C0 = ON

 

One operand is a discrete memory location, the other is an integer memory location.

 

The .Done member of a Timer structure indicates whether the Timer Preset value has been reached.

 

The result is placed in a discrete memory location.

 

 

Casting Numeric Values: assume X0 = ON and DLV2000 = 0x80

 

C0 = X0 && DLV2000:7

 

C0 = ON && 1

C0 = TRUE && TRUE

C0 = ON

 

One operand is a discrete memory location, the other is using the 'bit pick' cast operator which will examine the ON/OFF status of the bit at the specified position in the specified value.

 

The result is placed in a discrete memory location.

 

DLV memory locations are 16-bit Unsigned used by external DirectLOGIC devices. In this example a remote DirectLOGIC CPU has written a value of 0x0080 into DLV2000. The :7 cast operator will examine the state of the 8th bit (bit positions are 0-based) of the value in DLV2000.

 

 


See Also:

Add

Subtract

Multiply

Divide


Modulus / Remainder

Raise to a Power


Less Than

Less than or Equal To

 

Equal To

Not Equal To

 

Greater Than

Greater Than or Equal To


Logical AND

Logical OR


Bit-wise AND

Bit-wise OR

Bit-wise XOR


Shift Left

Shift Right

Unsigned Shift Right

 

Negate

Bit-wise Invert

Logical NOT

 


Related Topics:

MATH - Calculate Expression