Work it through
Compare the same bits
logic signed [7:0] s = 8'hFF; logic [7:0] u = 8'h01; Compare s < u with $signed(s) < $signed(u).
The bits never change; the first comparison is false and the second true.
Your next page is on its way.
Chapter 1 · Values & layout
Separate value domain from driver semantics, then read packed and unpacked dimensions as an explicit layout contract.

A worked mechanism
The other operand can change how a signed value is compared.
s = 8'shFF; u = 8'h01
Both vectors are eight bits.
s < u → 255 < 1 → 0
The unsigned operand makes this eight-bit comparison unsigned.
$signed(s) < $signed(u) → −1 < 1 → 1
Both operands now have signed interpretation.
Work it through
logic signed [7:0] s = 8'hFF; logic [7:0] u = 8'h01; Compare s < u with $signed(s) < $signed(u).
The bits never change; the first comparison is false and the second true.
Casting only s does not help: it was already signed. If u can exceed 127, converting it to signed changes its intended value too.
Assert both results using these exact widths. Choose a common type that represents the real ranges before generalizing.
The language bench / 01
logic [7:0] source = 8'b10100110;
logic [7:0] value = source;
// value = 8'b10100110, decimal: 166Question-first preparation
Each question maps directly to one of the sections below, so you can test the contract before reading the explanation.
One representative prompt from each major mechanism. Open any card in the live question bank.
Value systems and objects
Read the value domain and object kind separately, then check the legal combinations: built-in nets require four-state data, while variables may use two-state or four-state types.
Two independent axes
Stores 0, 1, X, or Z; normally one procedural owner.
Carries resolved values from continuous or module drivers.
Stores binary values; assigning X/Z collapses diagnostic state.
Built-in nets such as wire require four-state data. User-defined nettypes follow separate rules.
Stores 0, 1, X, or Z; normally one procedural owner.
Read the value domain and object kind separately. The lower-right cell is excluded for built-in nets: wire bit is illegal; user-defined nettypes are a separate mechanism.
List the values that must remain observable, the number of drivers, and whether resolution is part of the interface contract.
Use 4-state logic where X/Z exposes initialization, contention, or tri-state behavior; use 2-state types where those states are intentionally collapsed.
A 2-state conversion can hide an X, while a variable with multiple procedural writers creates an ownership error rather than net resolution.
Lint driver ownership, assert knownness at protocol boundaries, and test conversions with 0, 1, X, and Z—not only nominal binary values.
X can mean uninitialized, conflicting, unknown, or intentionally pessimistic data; Z represents high impedance on resolved connectivity. Those meanings are valuable at control and interface boundaries. A 2-state assignment cannot preserve them, so conversion is a deliberate loss of information.
| Type | Width | States | Default signedness | Typical use |
|---|---|---|---|---|
| bit | user-shaped | 2 | unsigned | Compact models and flags |
| logic / reg | user-shaped | 4 | unsigned | RTL state and observability |
| byte | 8 | 2 | signed | Characters and small arithmetic |
| shortint | 16 | 2 | signed | Compact arithmetic |
| int | 32 | 2 | signed | Loop variables and models |
| integer | 32 | 4 | signed | Legacy 4-state arithmetic |
| longint | 64 | 2 | signed | Wide arithmetic |
A net represents connectivity and may combine multiple drivers according to its net type. A variable stores the last assignment and should have a clear writer. In ports, spell out both object and data type when ambiguity would affect ownership.
wire logic resolved_irq;
logic sampled_irq;
bit model_enable;
assign resolved_irq = irq_a;
assign resolved_irq = irq_b; // net resolution is intentional
always_ff @(posedge clk) begin
sampled_irq <= resolved_irq; // one procedural owner
end
assert property (@(posedge clk) model_enable |-> !$isunknown(sampled_irq));Explain it out loud
No. logic is a four-state variable data type. A declaration can still be a net or a variable depending on syntax and context, and that object kind controls driving and resolution.
A strong answer separates data type from object kind and mentions driver ownership.
Saying “logic can always be driven from anywhere” ignores port defaults, continuous drivers, and single-writer intent.
Both are 32-bit signed integral types, but int is 2-state and integer is 4-state. Choose based on whether X/Z observability is part of the model.
The key distinction is state domain, not width or signedness.
Calling int four-state because logic is commonly used beside it.
Fixed arrays and dimensionality
Range placement changes arithmetic, slicing, assignment compatibility, memory inference, and the order in which bits travel through a conversion.
Shape before syntax
Sixteen contiguous bits; integral operators and slices apply.
Four independently indexed packed elements.
$bits reports the complete fixed-size object.
Sixteen contiguous bits; integral operators and slices apply.
A multidimensional declaration is a layout contract. Name each axis before writing a cast, slice, port, or DPI adapter.
Mark every packed dimension before the identifier and every unpacked dimension after it, including typedef-expanded dimensions.
Use packed arrays for vectors and fields that participate in integral operations; use unpacked arrays for independently indexed elements or memories.
Treating an unpacked byte array as a word creates assignment errors or an unintended reordering at the adapter.
Check $bits, $dimensions, $left, $right, $low, $high, and explicit boundary examples with non-symmetric values.
Packed arrays form one contiguous integral value. Unpacked arrays are collections of values. Both can have many dimensions, and typedefs can hide part of the shape, so APIs should document element type and dimension order.
typedef logic [7:0] byte4_t [0:3];
logic [1:0][7:0] lane [0:3];
byte4_t bytes;
initial begin
assert ($bits(lane) == 64);
lane[2][1] = 8'hA5;
lane[2][0][3 +: 4] = 4'hC;
endArray query functions make generic code resilient to range direction and typedef changes. For a mixed array, dimension numbers enumerate unpacked dimensions first and then packed dimensions, so name the queried dimension instead of assuming a memory layout.
| Query | Answers | Review use |
|---|---|---|
| $bits(expr) | Total bit count of a fixed-size value or type | Serialization and DPI widths |
| $dimensions(expr) | Total dimensions | Generic shape checks |
| $unpacked_dimensions(expr) | Unpacked dimensions | Memory and array adapters |
| $size(expr, n) | Elements in dimension n | Bounds-independent loops |
| $left / $right | Declared endpoints | Direction-preserving traversal |
| $low / $high | Numeric endpoints | Order-independent range checks |
| $increment(expr, n) | +1 descending, -1 ascending | Subtract it to move from $left to $right |
Explain it out loud
Packed dimensions create one contiguous integral value; unpacked dimensions create a collection of elements. That difference controls operators, slicing, assignment compatibility, and often implementation intent.
Use a concrete declaration and explain where its bits and elements live.
Reducing the distinction to syntax without explaining operations or layout.
No. Those ranges define index direction and significance within a SystemVerilog object. Memory byte order is a separate interface convention that must be specified at the boundary.
The answer should separate language indexing from architecture-level byte order.
Assuming a range direction automatically defines memory layout.