Altifigence Academy

25 / 36 · Concetto

Vector direction and bit indices

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

La traduzione non è ancora disponibile. Viene mostrata la lezione originale. (English)

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].

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

Prova tu

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

Leggi la spiegazione

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

La scelta vale per questo browser. Puoi modificarla in qualsiasi momento dal piè di pagina.