**Modulo Operator with Negative Operands** What is the value of mod1 and…
**Modulo Operator with Negative Operands** What is the value of mod1 and mod2 ? integer mod1, mod2; initial begin mod1 = -10 % 3; mod2 = 10 % -3; end
- mod1 = -1, mod2 = -1
- mod1 = -1, mod2 = 1
- mod1 = 1, mod2 = -1
- mod1 = 1, mod2 = 1
Correct answer
B. mod1 = -1, mod2 = 1
Explanation
In Verilog, the result of a modulo operation ( % ) inherits the sign of the **first operand** (the dividend). For -10 % 3 , the dividend is negative, so mod1 = -1 . For 10 % -3 , the dividend is positive, so mod2 = 1 .