Skip to content
DenseChip
Learn
PracticeCode labInterview

DenseChip

Navigate

Menu

LearnPracticeCode labInterview

Tools

All toolsSV editorCode repoResume
DenseChip

Practice, courses, and chip-design tools in one focused workspace.

LearnPracticeCode labInterviewToolsLearning paths

© 2026 DenseChip

AboutRoadmapCareersInternshipsFAQContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
    • Datatype and Bit Puzzles
      • X-Bit Comparisons and Mixed Arithmetic
      • Signed vs Unsigned Comparison Trap
      • Type Cast Controls Sign Extension
      • Signed Part-Select Is Still Unsigned
      • X Collapse into 2-State `int`
      • Expression Width Drops the Carry
    • Fork Join Puzzles
    • Queue and Array Puzzles
    • String and Casting Puzzles
    • SystemVerilog Language Puzzles: Tricky Q&A
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • Study Route: One Week Before the Interview
  • Study Route: Two Weeks
  • Study Route: Four Weeks (Full Course)4
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • UVM Testbench Puzzles25
  • Clock, Reset & CDC Puzzles25
  • Bus and Interface Protocol Puzzles25
  • Interview Prep: Puzzle Rounds7
  • DV Puzzle Cheatsheet
Loading lesson

←Datatype and Bit Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. SystemVerilog Language Puzzles
  4. Datatype and Bit Puzzles
  5. Signed Part-Select Is Still Unsigned
On this page

    VLSI DV Interview PuzzlesAll levels

    Signed Part-Select Is Still Unsigned

    Predict all five lines and explain which expressions are evaluated as unsigned.

    Puzzle

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

    Predict all five lines and explain which expressions are evaluated as unsigned.

    Code

    p4.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    module p4;
      logic signed [7:0] s = -8'sd2; // 1111_1110
      initial begin
        $display("slice=%0d", s[7:4]);
        $display("signed_slice=%0d", $signed(s[7:4]));
        $display("shift=%0d", s >>> 4);
        $display("cmp=%0d signed_cmp=%0d", s[7:4] > 4'sd0, $signed(s[7:4]) > 4'sd0);
        $display("plus=%0d", s[7:4] + 4'sd1);
      end
    endmodule

    Hint

    Part-select expressions lose signedness unless you cast them. `>>>` uses the signedness of the left operand. Once any operand of a comparison or an addition is unsigned, the whole expression is unsigned.

    Step-by-step solution

    Diagram
    1) `s[7:4]` is 4'b1111 but a part-select expression is unsigned by default, so decimal is 15.
    2) `$signed(s[7:4])` reinterprets 4'b1111 as signed -1.
    3) `s >>> 4` arithmetic-shifts signed -2 to -1, so it matches line 2, not line 1.
    4) `s[7:4] > 4'sd0` mixes an unsigned part-select with a signed constant, so the compare is unsigned: 15 > 0 is 1. With `$signed(...)` both sides are signed: -1 > 0 is 0.
    5) `s[7:4] + 4'sd1` is an unsigned 4-bit add: 15 + 1 wraps to 0.

    Answer

    Answer: slice=15, signed_slice=-1, shift=-1, cmp=1 signed_cmp=0, plus=0

    How this was checked

    Checked by running the code in Icarus Verilog 13 and Verilator 5; the printed output supports the answer above. A part-select is unsigned until you cast it. (Icarus, 4-state) A part-select is unsigned until you cast it. (Verilator, 2-state)

    Why candidates get it wrong

    `s[7:4]` looks like a slice of a signed vector but is unsigned, so `s[7:4] > 4'sd0` is true (15 > 0) until you wrap it in `$signed`, and `s[7:4] + 4'sd1` wraps 15 to 0 instead of giving -1 + 1.

    Interviewer follow-up

    How would `s >> 4` differ from `s >>> 4` in this example? Model answer: `s >> 4` is a logical shift, it zero-fills even though s is signed, giving 8'b0000_1111 = 15; `s >>> 4` sign-fills and gives -1.

    Say it out loud

    I would remember that a part-select is always unsigned, even from a signed vector. So the slice prints 15, the signed cast of the slice is minus 1, and the arithmetic shift of the whole signed value gives minus 1 as well. The compare of the plain slice against zero is unsigned, so true, but with the signed cast it is minus 1 against 0, which is false, and the plain add wraps 15 plus 1 to 0. The trap is trusting that the slice inherits the sign. I would check each place a slice enters a comparison or an add.

    Related topics

    • Signed & Unsigned Arithmetic

    • Shifts, Concatenation & Streaming

    • Back to Datatype and Bit Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    9 / 293

    Next: Study Route: Two Weeks

    Up next

    Up nextStudy Route: Two Weeks

    Sign in to save progress

    Practice this lessonPrevious lessonReport an error

    See also

    • X-Bit Comparisons and Mixed Arithmetic
    • Signed vs Unsigned Comparison Trap
    • X Collapse into 2-State `int`