EECS 31L | EX-102 | Verilog Operators

Modules are the basic building blocks in Verilog used to encapsulate functionality.

Document version: v0.3a
Last modified: 2026-05-28 22:41
Canvas: [ EECS 31L Workspace ]
All questions concern Verilog operators. Treat all values as unsigned unless stated otherwise.
Part 1 — Arithmetic.
Q1: Evaluate each expression. Express the result as an unsigned decimal value.

4'd9    + 4'd3    =
4'b1111 - 4'b0110 =
4'hC    / 4'h3    =
4'hF    + 4'h2    =
4'b0011 - 4'b0101 =
4'd12   + 4'd6    =
💡 HintWhen doing arithmetic operations, pay attention to the number of bits allocated and whether the result would fit within that number of bits.
Part 2 — Relational.
Q2: Evaluate each expression. Result is 1-bit.

5'd9   == 4'd9  =
4'd9   == 3'd9  =
4'b1100 != 4'b1100 =
4'hB   > 4'hA  =
4'd5   >= 4'd5  =
4'b0011 < 4'b0010 =
💡 HintRelational operators compare two values. The result is always 1-bit, where 1 means true and 0 means false.
Part 3 — Logical vs Bitwise.
Q3: Evaluate each expression.

3'b101 && 3'b011 =
3'b101 || 3'b000 =
3'b000 && 3'b111 =
!3'b101          =
!3'b000          =
💡 HintThe operators used above (&&, ||, !) are called logical operators. They operate on the value as a whole, not bit by bit, and always produce a 1-bit result.
Q4: Evaluate each expression. Give result in binary.

3'b101 & 3'b011 = 3'b
3'b101 | 3'b011 = 3'b
3'b101 ^ 3'b011 = 3'b
~3'b101         = 3'b
💡 HintThe operators used above (&, |, ^, ~) are called bitwise operators. Unlike logical operators, they operate independently on each pair of corresponding bits and produce an N-bit result.
Q5: Fill in the missing operand or operator.

3'b101 3'b011 = 1'b1  
3'b101 3'b011 = 3'b001  
3'b101 = 3'b010  
3'b101 = 1'b0  
💡 HintReduction operators (&, |, ^) are unary — they take a single operand and collapse all its bits into a single 1-bit result by applying the operation between consecutive bits.
Part 4 — Reduction.
Q6: Evaluate the following expressions. Provide your answers in binary format.

&4'b1111  =
&4'b1101  =
|4'b0000  =
|4'b0010  =
^4'b1101  =
^4'b1100  =
Q7: Fill in the missing operand.

& = 1'b1   (4-bit value)
| = 1'b0   (4-bit value)
^ = 1'b1   (4-bit value, give one valid answer)
Part 5 — Shift.
Q8: Evaluate each expression. Give result in binary.

4'b1011 << 1 = 4'b
4'b1011 << 2 = 4'b
4'b1011 >> 1 = 4'b
4'b1011 >> 2 = 4'b
💡 HintThe << and >> operators are called logical shift operators. Think about what happens to the bits that are shifted out, and what fills the vacated positions.
Q9: Evaluate each expression. Give result in binary.

4'b1011 <<< 1 = 4'b
4'b1011 >>> 1 = 4'b
4'b0101 >>> 1 = 4'b
💡 HintThe <<< and >>> operators are called arithmetic shift operators. Consider how >>> differs from >> when the MSB is 1 versus 0.
Q10: Fill in the missing shift amount.

4'b0011 << = 4'b1100
4'b1100 >> = 4'b0011
4'b0001 << = 4'b1000
Part 6 — Concatenation and Replication.
Q11: Evaluate each expression. Give result in binary.

{4'b1010, 4'b0101}      = 8'b
{1'b1, 3'b010}         = 4'b
{2'b11, 2'b0, 2'b10} = 6'b
💡 HintThe operator {} is called concatenation. It combines multiple operands into a single result by placing them side by side. The order of the operands determines which bits occupy the most significant positions in the result.
Q12: Evaluate each expression. Give result in binary.

{4{1'b1}}       = 4'b
{3{2'b10}}     = 6'b
{2{3'b101}}    = 6'b
💡 HintThe {} operator is called concatenation. Think about which operand occupies the most significant bits in the result.
Q13: Fill in the missing operand or replication count.

{{1'b0}}              = 8'b00000000
{2'b1, {2'b01}}     = 8'b   (give replication count)
{{}} = 6'b110110
💡 HintThe {n{X}} syntax is called replication. Think about the total bit-width of the result.
Part 7 — Conditional.
Q14: The conditional operator condition ? val_if_true : val_if_false.

1'b1 ? 4'd10 : 4'd5   =
1'b0 ? 4'd10 : 4'd5   =
(4'd3 > 4'd2) ? 4'd1 : 4'd0 =
(4'd3 == 4'd4) ? 4'd1 : 4'd0 =
Q15: Fill in the missing condition or value.

() ? 4'd7 : 4'd3 = 4'd3   (use a simple comparison)
1'b1 ? : 4'd0 = 4'd9
1'b0 ? 4'd9 : = 4'd4
💡 HintThe ?: operator is called the conditional (or ternary) operator. Which branch is evaluated when the condition is 0?