25 / 36 · Khái niệm
Vector direction and bit indices
Read q[2:0] and identify the positions selected by a slice.
Bài học miễn phí. Đăng ký để lưu tiến độ học tập.
Chưa có bản dịch. Nội dung bài học gốc được hiển thị. (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.
| q | q[2] | q[1] | q[0] | q[1:0] |
|---|---|---|---|---|
| 101 | 1 | 0 | 1 | 01 |
| 110 | 1 | 1 | 0 | 10 |
| 011 | 0 | 1 | 1 | 11 |
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].
logic [2:0] q;
// q = 3'b101: q[2]=1, q[1]=0, q[0]=1
// q[1:0] = 2'b01Tự thử
For q=110, what are q[1:0] and q[2]?
Đọc giải thích
q[1:0]=10 and q[2]=1. The slice is written in the order q[1], q[0].