9 / 24 · Concept
Bit width and binary values
Read the values and bit positions of a two-bit number.
Lessons are free to read. Enroll to save your learning progress.
Learning goals
- Calculate the weight of each bit
- Distinguish a numeric value from the width holding it
Four values in two bits
logic [1:0] count contains count[1] and count[0]. For an unsigned value their weights are 2 and 1. Binary 10 therefore means two, not decimal ten.
Two bits have four combinations. Storing four needs more bits. A register does not automatically grow when a calculation produces a larger value.
| Bits [1:0] | Calculation | Decimal |
|---|---|---|
| 00 | 0 × 2 + 0 × 1 | 0 |
| 01 | 0 × 2 + 1 × 1 | 1 |
| 10 | 1 × 2 + 0 × 1 | 2 |
| 11 | 1 × 2 + 1 × 1 | 3 |
Read the width and base of a literal
In 2'b01, 2 is the bit width, b means binary and 01 is the value. The expression count + 2'b01 adds one. Check that the literal and your table describe the same value.
The initial-value array used by this example starts with the least significant bit. count=10 is [false, true]. Copying the written bits from left to right would reverse their positions.
logic [1:0] count;
// Two-bit unsigned values: 00, 01, 10, 11
// Increment value: 2'b01Try it yourself
What is count for the LSB-first array [true, false]?
Read the explanation
count[0]=1 and count[1]=0, giving binary 01, or decimal one.