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

AboutContactPrivacyTerms
Skip to lesson

Course contents

  • How to Use This Puzzle Bank
  • SystemVerilog Language Puzzles25
    • Datatype and Bit Puzzles
    • Fork Join Puzzles
    • Queue and Array Puzzles
    • String and Casting Puzzles
      • String Substr with Runtime Class Cast
      • putc/getc Index Semantics
      • Case-Sensitive vs Case-Insensitive Compare
      • Enum Safety with $cast
      • Failed Class Cast Leaves Old Handle
      • String Number Parsing Stops Early
    • SystemVerilog Language Puzzles: Tricky Q&A
  • Difficulty Guide
  • Full Topic Map
  • Interview-Day Tips
  • OOP & Testbench Puzzles25
  • Concurrency & Timing Puzzles25
  • Randomization & Constraint Puzzles25
  • SVA Assertion Puzzles25
  • Functional Coverage Puzzles25
  • Logic & Aptitude Puzzles25
  • Scenario & Debug Puzzles25
  • Interview Prep: Puzzle Rounds5
  • DV Puzzle Cheatsheet
Loading lesson

‹String and Casting Puzzles
  1. Topics
  2. DV Interview Puzzles
  3. SystemVerilog Language Puzzles
  4. String and Casting Puzzles
  5. String Number Parsing Stops Early

VLSI DV Interview Puzzles · All levels

String Number Parsing Stops Early

What values do `atoi` and `atohex` return here?

On this page

    Puzzle

    Difficulty: Medium · Puzzle 6 of 6 · Topic: String and Casting Puzzles

    What values do `atoi` and `atohex` return here?

    Code

    p6.sv
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    module p6;
      string s1 = "1234";
      string s2 = "12x3";
      string s3 = "1f";
      int d1, d2, h1;
      initial begin
        d1 = s1.atoi();
        d2 = s2.atoi();
        h1 = s3.atohex();
        $display("d1=%0d d2=%0d h1=%0d", d1, d2, h1);
      end
    endmodule

    Hint

    `atoi` reads decimal digits from start and stops at first non-digit. `atohex` interprets hex digits.

    Step-by-step solution

    Diagram
    1) `"1234".atoi()` consumes all digits -> 1234.
    2) `"12x3".atoi()` stops at `x`, so value is 12.
    3) `"1f".atohex()` parses as hex 0x1F -> 31.

    Answer

    Answer: d1=1234, d2=12, h1=31

    Why candidates get it wrong

    Interviewees often assume parse fails completely when non-digit appears mid-string.

    Interviewer follow-up

    What does `"x123".atoi()` return, and why?

    Related topics

    • Back to String and Casting Puzzles

    • SystemVerilog Language Puzzles section

    Previous

    28 / 210

    Next: SystemVerilog Language Puzzles: Tricky Q&A

    Up next

    Up nextSystemVerilog Language Puzzles: Tricky Q&A

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • String Substr with Runtime Class Cast
    • putc/getc Index Semantics
    • Case-Sensitive vs Case-Insensitive Compare