Academy
English한국어

9 / 24 · Concept

Bit width and binary values

Read the values and bit positions of a two-bit number.

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]CalculationDecimal
000 × 2 + 0 × 10
010 × 2 + 1 × 11
101 × 2 + 0 × 12
111 × 2 + 1 × 13

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.

RTL excerpt
logic [1:0] count;
// Two-bit unsigned values: 00, 01, 10, 11
// Increment value: 2'b01

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

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