7 / 37 · Concept
Widths of slices, concatenations and replications
Build datapaths by calculating concatenated widths and the conditions for preserving values.
Lessons are free to read. Enroll to save your learning progress.
Concatenation is not addition
{a,b} appends b's bits after a's bits. If their widths are M and N, the result width is M+N. For two unsignedUnsigned A rule for interpreting a bit pattern as a nonnegative integer. The n-bit range is 0 through 2^n−1 and may differ from the signed interpretation of the same bits. Learn more bit patterns, numerically
With a=2'b10 and b=3'b101, concatenation gives 5'b10101, or 21, not the arithmetic sum 7.
a's bits move upward by b's width. Read this concatenationConcatenation An operation that joins bit patterns side by side. Its result width is the sum of the operand widths; it is not numerical addition. as a×2³+b, not a+b.
- a = 10: Width 2 bits, integer 2
- b = 101: Width 3 bits, integer 5
- {a,b} = 10101: Width 5 bits, 2×8+5=21
Write the width beside each expression
logic [7:0] word;
logic [3:0] upper, lower;
logic [7:0] swapped;
assign upper = word[7:4];
assign lower = word[3:0];
assign swapped = {lower, upper};Input 8'hA3 gives swapped=8'h3A. An incorrect sliceSlice An operation selecting a contiguous range of bits from a vector. The selected range determines the result width and bit order. boundary changes the width or value. A part-select can be treated as a separate unsigned value even when the original vector is signed, so recheck its meaning before signed arithmetic.
Sign extension and replication
logic signed [3:0] small;
logic signed [7:0] extended;
assign extended = {{4{small[3]}}, small};Concatenate four copies of the sign bit with the original four bits to make eight. Sign extension is not adding 1 because the MSBMSB The bit with the highest place value. Its index depends on the vector's declaration direction, so do not assume it always has the largest index. Learn more is 1; it widens the bit representation while preserving the interpreted value.
A generic shift circuit using q[N-2:0] has an invalid range at N=1. Restrict the minimum supported width or handle N=1 in a separate generate branch. Parameterization is more than replacing numbers with variables.
Try it yourself
a is three-bit 101 and b is two-bit 11. What are the width and value of {a,b}? What remains if it is stored in four bits?
Read the explanation
The width is five bits, the pattern is 10111 and the value is . Four-bit storage discards the upper bit, leaving 0111, or 7.