Academy
English한국어

17 / 24 · Concept

Vector direction and bit indices

Read q[2:0] and identify the positions selected by a slice.

Learning goals

  • Locate each bit of a vector
  • Distinguish a slice from the complete value

Map written digits to bit indices

logic [2:0] q contains q[2], q[1] and q[0]. For q=101, the leftmost 1 is q[2], the middle 0 is q[1] and the rightmost 1 is q[0]. An index identifies a position, not a value.

q[1:0] selects the low two bits. With q=101 the slice is 01. Only those selected bits, not the entire old q, participate in the following concatenation.

qq[2]q[1]q[0]q[1:0]
10110101
11011010
01101111

Count the widths to see the connection

q[1:0] is two bits and din is one bit. Together they form three bits, exactly the width of q. Recording widths helps reveal accidental truncation or extension.

Arrays in input and initialization settings may use a different order from a written binary number. This example uses LSB-first initial values, so q=100 is [false, false, true].

RTL excerpt
logic [2:0] q;
// q = 3'b101: q[2]=1, q[1]=0, q[0]=1
// q[1:0] = 2'b01

Try it yourself

For q=110, what are q[1:0] and q[2]?

Read the explanation

q[1:0]=10 and q[2]=1. The slice is written in the order q[1], q[0].

Your choice applies to this browser. Change it any time using the footer.