contents.gifindex.gif

Relational Operators

Operator

Result

Description

==

Equal

Double equal sign

!=

Not equal

exclamation point/equal sign

<

Less than

left angle bracket

<=

Less than or equal

left angle bracket/equal sign

>

Greater than

right angle bracket

>=

Greater than or equal

right angle bracket/equal sign

Relational operators are used to compare two items in an expression. Expressions formed with relational operators produce a Boolean true or false value.

All relational operations are unsigned. For example, the expression !0 > 4 is true since the complement of !0 is 1111 (assuming 4 bits of data), which is 15 in unsigned binary, and 15 is greater than 4. For the purpose of this example, a four-bit representation was assumed; in actual use, !0, the complement of 0, is 32 bits all set to 1.

Example

Expression

Value

2 == 3

False

2 != 3

True

3 < 5

True

-1 > 2

 True

The logical values, true and false, are represented internally by numbers. Logical true is -1 in twos complement: all 32 bits are set to 1. Logical false is 0 in twos complement so all 32 bits are set to 0. This means that an expression producing a true or false value (a relational expression) can be used anywhere a number or numeric expression could be used and -1 or 0 will be substituted in the expression depending on the logical result.

For example, A = D $ (B == C); means that

A equals the complement of D if B equals C

A equals D if B does not equal C.

When using relational operators, always use parentheses to ensure the expression is evaluated in the order you expect. The logical operators & and # have a higher priority than the relational operators. The following equation

Select = [A15..A0] == ^hD000 # [A15..A0] ==<N>^h1000;

has the default parentheses grouping

Select = [A15..A0] == (^hD000 # [A15..A0]) ==<N>^h1000;

which is not the intended equation. To get the desired results, write the equation as follows:

Select = ([A15..A0] == ^hD000) # ([A15..A0] ==<N>^h1000);


See Also

Logical Operators

Arithmetic Operators

Assignment Operators