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

  • RTL Foundations36
    • Digital Logic for RTL Engineers
    • Number Systems for RTL Engineers
    • Verilog Fundamentals
    • Verilog Operators and Types
      • Width Discipline
      • Bit Vectors and Slicing
      • Concatenation and Replication
      • Reduction and Logical Operators
      • Shift and Arithmetic Intent
      • Parameterized, Type-Safe Design
    • SystemVerilog for RTL
    • Simulation and Testbenches
  • Combinational Design25
  • Sequential Design27
  • FSM & Control27
  • Timing & Clocking39
  • Reset & CDC34
  • Memory & Buses57
  • Advanced RTL28
  • Senior & Interview76
  • Glossary and Notation
Loading lesson

‹RTL Foundations
  1. Topics
  2. RTL Design
  3. RTL Foundations
  4. Verilog Operators and Types

Part 1 · Foundations · Beginner

Verilog Operators and Types

Width rules, selects, concatenation, reduction, shifts and parameters for datapaths.

  • 6topics
  • 6lessons

Topics in this section

  1. 1Width Discipline1 lesson
  2. 2Bit Vectors and Slicing1 lesson
  3. 3Concatenation and Replication1 lesson
  4. 4Reduction and Logical Operators1 lesson
  5. 5Shift and Arithmetic Intent1 lesson
  6. 6Parameterized, Type-Safe Design1 lesson
On this page

    Widths decide whether operator logic is correct. This topic covers vectors, selects, concatenation, reduction, shifts and parameters, with habits that keep widths explicit.

    Operand widths feed context-determined expression width, then the operation, then truncation or extension.
    Width is decided before the operation runs. The left-hand side is part of the context.

    Lessons in this topic

    6 lessons, about 21 min

    1. 1Width DisciplineYou can predict the width at which an expression is evaluated, and size operands, results and carries so no bits are lost by accident.4 min
    2. 2Bit Vectors and SlicingYou can select bits, fixed fields and variable byte lanes, and say which selects are wiring and which build a mux.4 min
    3. 3Concatenation and ReplicationYou can build byte swaps, rotations, sign extensions and constant patterns with concatenation and replication.3 min
    4. 4Reduction and Logical OperatorsYou can choose bitwise, reduction or logical operators, write flag idioms, and compare values that may contain x.4 min
    5. 5Shift and Arithmetic IntentYou can choose the right shift, say what it costs in hardware, and write arithmetic that shows its intent.3 min
    6. 6Parameterized, Type-Safe DesignYou can choose parameters and localparams, size an address with $clog2 safely, and reject illegal values at elaboration.3 min
    Check yourself wire [7:0] y = a_8bit + b_16bit; What width is the addition performed in, and what happens to y?

    The addition is performed in 16 bits (the widest operand), then truncated to the low 8 bits for y. If you wanted the full result you must declare y at least 17 bits wide.

    Interview

    “What is the width of a + b if both are 4-bit and the result goes to a 5-bit signal?” The answer (5, and the carry is kept) is the first lesson.

    Revision sheet

    The whole topic on one page, taken from each lesson's Remember box. Read it before an interview, or print it.

    Width Discipline

    • Context-determined arithmetic uses the widest operand or target. A concatenation operand is self-determined and does not.

    • Size every literal, and capture the carry with a concatenated target: {carry, sum} = a + b.

    • An unsized 0 in a comparison makes the whole expression at least 32 bits wide.

    Rule of thumb: give every intermediate N+1 bits for an add and 2N for a multiply.

    Bit Vectors and Slicing

    • Declare [N-1:0] so the MSB is on the left. Avoid ascending ranges for data.

    • A part-select needs constant bounds. Use base +: WIDTH when only the start varies.

    • An out-of-range read gives x and an out-of-range write is ignored.

    Rule of thumb: name the fields of a packed word instead of scattering magic bit numbers.

    Concatenation and Replication

    • {a, b} puts a in the upper bits. Every element needs a known width, and the total is their sum.

    • {N{x}} needs a constant N.

    • A concatenation is valid on the left of an assignment, which splits a result: {carry, sum} = a + b.

    Rule of thumb: rotate by joining a slice with the bit that wraps.

    Reduction and Logical Operators

    • Reduction operators (&v, |v, ^v) collapse a vector to one bit: all-ones, any-one, parity.

    • == gives x when unknown bits decide the answer; === and !== compare x and z literally and belong in testbenches only.

    • Use !== in self-checking tests so an x output counts as a mismatch.

    Rule of thumb: bitwise for bits, logical for conditions.

    Shift and Arithmetic Intent

    • Shifting by a constant is wiring. A variable shift is a mux network whose depth grows with the shift width.

    • Arithmetic right shift rounds toward minus infinity and division truncates toward zero.

    • Division and modulo by a non-power-of-two are slow in one cycle; restructure or use a multi-cycle divider.

    Rule of thumb: write a << 3 or a * 8, whichever reads as your intent. They synthesise the same.

    Parameterized, Type-Safe Design

    • Parameters are the true design choices; derive everything else with localparams.

    • $clog2(n) is the ceiling of log2 n. Guard DEPTH = 1, and size constants to the counter width.

    • Check illegal values at elaboration with $error, and prefer typed parameters.

    Rule of thumb: derive each width from one parameter, never from a second copy of the number.

    Practise it

    • Mini project: a 4-bit ALU with flags and an exhaustive bench

    • Code lab: Build an even parity generator

    • Practice question: Barrel shifter with left, right and rotate modes

    • Code lab: Build a barrel shifter

    • Practice question: 2x1 multiplexer with parameterized width

    • Interview: run a mock interview on this topic

    PreviousNext: Width Discipline

    Up next

    Up nextWidth Discipline

    Sign in to save progress

    Practice this lessonReport an error

    See also

    • Digital Logic for RTL Engineers
    • Number Systems for RTL Engineers
    • Verilog Fundamentals