Binary arithmetic operators operate on two operands. Register and net (wire) operands are treated as unsigned. However, real and integer operands may be signed. If any bit is unknown ('x') then result is unknown.
Relational operators compare two operands and return a logical value, i. e., TRUE(1) or FALSE(0). If any bit is unknown, the relation is ambiguous and the result is unknown.
Operator Name
> Greater than
>= Greater than or equal
< Less than
<= Less than or equal
== Logical equality
!= Logical inequality
Logical Operators
Logical operators operate on logical operands and return a logical value, i. e., TRUE(1) or FALSE(0). Used typically in if and while statements. Do not confuse logical operators with the bitwise Boolean operators. For example , ! is a logical NOT and ~ is a bitwise NOT. The first negates, e. g., !(5 == 6) is TRUE. The second complements the bits, e. g., ~{1,0,1,1} is 0100.
Operator Name
! Logical negation
&& Logical AND
|| Logical OR
Bitwise Operators
Bitwise operators operate on the bits of the operand or operands. For example, the result of A & B is the AND of each corresponding bit of A with B. Operating on an unknown (x) bit results in the expected value. For example, the AND of an x with a FALSE is an x. The OR of an x with a TRUE is a TRUE.
Operator Name
~ Bitwise negation
& Bitwise AND
| Bitwise OR
^ Bitwise XOR
~& Bitwise NAND
~| Bitwise NOR
~^ or ^~ Equivalence Bitwise NOT XOR
Unary Reduction Operators
Unary reduction operators produce a single bit result from applying the operator to all of the bits of the operand. For example, &A will AND all the bits of A.
Operator Name
& AND reduction
| OR reduction
^ XOR reduction
~& NAND reduction
~| NOR reduction
~^ XNOR reduction
Other Operators
The conditional operator operates much like in the language C.
Operator Name
=== Case equality
!== Case inequality
{ , } Concatenation
<< Shift left
>> Shift right
?: Conditional
Case equality : The bitwise comparison includes comparison of x and z values. All bits must match for equality. Returns TRUE or FALSE.
Case inequality : The bitwise comparison includes comparison of x and z values. Any bit difference produces inequality. Returns TRUE or FALSE.
Concatenation : Joins bits together with 2 or more comma-separated expressions, e, g. {A[0], B[1:7]} concatenates the zeroth bit of A to bits 1 to 7 of B.
Shift left : Vacated bit positions are filled with zeros, e. g., A = A << 2; shifts A two bits to left with zero fill.
Shift right : Vacated bit positions are filled with zeros.
Conditional : Assigns one of two values depending on the conditional expression. E. g., A = C>D ? B+3 : B-2 means if C greater than D, the value of A is B+3 otherwise B-2.
Operator Precedence
The precedence of operators is shown below. The top of the table is the highest precedence and the bottom is the lowest. Operators on the same line have the same precedence and associate left to right in an expression. Parentheses can be used to change the precedence or clarify the situation. We strongly urge you to use parentheses to improve readability.