VLSI DV Interview Puzzles · All levels

X Collapse into 2-State `int`

Predict all lines and explain why `i` and `w` disagree about unknown data.

Puzzle

Difficulty: Medium · Puzzle 5 of 6 · Topic: Datatype and Bit Puzzles

Predict all lines and explain why `i` and `w` disagree about unknown data.

Code

systemverilog
module p5;
  logic [3:0] l = 4'b10x1;
  int i = l;
  logic [31:0] w = l;
  initial begin
    $display("i=%0d", i);
    $display("w=%h", w);
    $display("w==32'h9 -> %b", w == 32'h0000_0009);
    $display("w===32'h9 -> %0d", w === 32'h0000_0009);
  end
endmodule

Hint

`int` is 2-state, but `logic [31:0]` is 4-state. Compare `==` versus `===` separately.

Step-by-step solution

diagram
1) Assigning `l` into 2-state `int i` collapses x to 0, so `i` becomes 9.
2) Assigning to 4-state `w` preserves unknown in low nibble, so hex print includes x.
3) `w == 9` returns x because unknown participates in logical equality.
4) `w === 9` returns 0 because case equality requires exact bit match and x does not equal 0 or 1.

Answer

Answer: i=9, w has an x nibble (for example 0000000x), `w==...` is x, `w===...` is 0

Why candidates get it wrong

Candidates memorize that X is preserved, but forget 2-state scalar types silently coerce it away.

Interviewer follow-up

What type change would keep `i` 32-bit wide but preserve X/Z information?

Related topics