Altifigence Academy

2 / 63 · Concept

Number systems and fixed-width representations

Go beyond base conversion to calculate representable ranges, required bit widths and truncation effects.

Where this course begins

High-school algebra and basic programming experience are recommended. Binary numbers and Boolean algebraBoolean algebra Algebra of 0, 1, AND, OR and NOT. Here, the plus sign usually means OR, so its rules differ from integer addition. Learn more are covered within the course, which moves briskly at an introductory university level. Focus on specifying input conditions, bit widths and observation times, then checking examples, rather than memorizing formulas.

Distinguish bit patterns from values

A circuit stores a finite bit pattern. The design contract determines whether to interpret it as an integer, a signed value or fixed-pointFixed-point A number representation with a predetermined binary-point position, applying a fixed scale to an integer bit pattern. Specify width, signedness and the number of fractional bits together. Learn more data. The range calculations needed in RTL build on integer arithmetic and powers.

An NN-bit unsignedUnsigned A rule for interpreting a bit pattern as a nonnegative integer. An n-bit value ranges from 0 to 2^n−1 and may differ from the signed interpretation of the same bits. value is interpreted as

u=∑i=0N−1bi2i,0≤u≤2N−1u=\sum_{i=0}^{N-1}b_i2^i,\qquad 0\le u\le 2^N-1

10110110 equals 128+32+16+4+2=182128+32+16+4+2=182. Grouping it into four-bit chunks gives B6, so 8'hB6 and 8'b10110110 are the same bit pattern. Every hexadecimal digit represents four bits, making conversion quick when reading addresses, masks and waveforms.

Same bits, different interpretation

Toggle b7 below. Under an unsigned interpretation it contributes 128; under two's complementTwo's complement A representation of signed integers using fixed-width bit patterns. The n-bit range is −2^(n−1) through 2^(n−1)−1. Learn more, the most significant bit has weight −128. First construct 0x7F and 0x80 and compare the boundary between the two interpretations.

Bits and number representations

10110110 → unsigned 182 · signed -74 · hex 0xB6

Changing a bit pattern and interpreting it as signed are different operations. Even with the same eight-bit circuit width, comparison results depend on the signedness passed to the operator.

Determine the range before the width

The minimum number of bits needed to distinguish MM different states is

N=⌈log⁡2M⌉N=\left\lceil\log_2 M\right\rceil

Counting from 0 through 999 requires 1000 distinct values, hence 10 bits. From 0 through 1024 requires 1025 values, hence 11 bits. Confusing the maximum value with the number of states leaves you one bit short exactly at a boundary. If RTL parameters allow M=1M=1, constrain the width to at least 1 to avoid a zero-bit vector.

What happens when a result is stored in a narrower signal?

Unsigned storage that discards upper bits and retains only NN bits is a modulo operation:

xstored=x mod 2Nx_{stored}=x\bmod 2^N

For example, storing the nine-bit result 300 in eight bits leaves 44. This is neither rounding nor saturation. Saturation requires separate logic that detects an out-of-range result and selects the maximum value.

SystemVerilog
logic [7:0] a, b, low;
logic [8:0] full_sum;
assign full_sum = {1'b0, a} + {1'b0, b};
assign low = full_sum[7:0];

Extending both operands first makes the intention to preserve the carry explicit. The number base alone does not determine signedness or result width. Interpreting a waveform requires width, signedness and radix together.

Try it yourself

How many bits are needed to count from 0 through 4095, and from 0 through 4096? What remains when 511 is stored in an 8-bit unsigned value?

Read the explanation

The first range contains 4096=2124096=2^{12} values, requiring 12 bits; the second contains 4097, requiring 13 bits. Since 511 mod 256=255511\bmod256=255, the stored value is 8'hFF. That alone does not establish that no overflow occurred.

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