The sensors in lesson one answered a single question: is this location too hot? One bit could carry that answer. Now the display needs a measurement value. The sensor interface sends eight bits, and the selector must pass the whole group. The selection rule stays familiar: sel=0 chooses A and sel=1 chooses B.
Suppose the display receives 1111_0000. Should it show 240 or −16? The bits alone do not decide the product’s answer. The interface must define how to read them. We will follow this one pattern through declarations, truncation, two’s complement and widening, then use actual simulation to catch a plausible mistake.
Follow the bits in the lesson film
Follow one value through notation, truncation, interpretation and widening. Revisit a chapter, then change the bits in the inspector.
Film chapters
Download MP4
Download captions VTT
Read the film transcript
Gemini TTS provides the US English narration. The animation illustrates signal relationships; actual RTL simulation results and source files are available below.
From one wire to eight bits
Lesson one wrote input wire a_i because the panel only needed one overtemperature bit. A measurement needs a wider input, written input wire [7:0] a_i. The range includes both endpoints, so the signal has eight positions. In this declaration, a_i[0] is the least significant bit and a_i[7] is the most significant bit. A drawing often uses one thick line, marked with its width, to represent the group. That group of data connections is commonly called a bus. The selecting element is a multiplexer, usually shortened to mux.
module channel_select_8b (
input wire [7:0] a_i, b_i,
input wire sel_i,
output wire [7:0] selected_o
);
assign selected_o = sel_i ? b_i : a_i;
endmodule
If A carries 8'hF0 and B carries 8'h25, the output is the complete pattern F0 when A is selected, or 25 when B is selected. The width says how many bit positions the signal has. It does not add storage. This remains a combinational selector: the output follows the selected input. Physical propagation delay depends on the implementation and timing analysis; this zero-delay RTL does not measure it.
Eight bits are often called a byte. Here that word describes an amount of data. SystemVerilog also has a type named byte, which we do not need in the main example. For now, keep the size of a signal separate from the meaning assigned to its bits.
F0 and 1111_0000 spell the same pattern
Divide the eight binary digits into two groups of four. 1111 is hexadecimal F, and 0000 is hexadecimal 0, giving F0. The underscore helps a person see the groups; it occupies no bit position.
In RTL, the constants 8'b1111_0000 and 8'hF0 describe the same eight-bit pattern. The leading 8 specifies the literal’s width. After the apostrophe, b selects binary and h selects hexadecimal. The remaining digits supply the pattern in that base. Octal uses o, and decimal uses d.[1]
logic [7:0] raw;
initial begin
raw = 8'b1111_0000;
$display("bits=%08b hex=%02h unsigned=%0d", raw, raw, raw);
end
This testbench prints the same signal in three formats: binary with %b, hexadecimal with %h and decimal with %d. Width settings in the format string control the printed layout. The declaration still determines the signal’s actual width. Since raw is an unsigned eight-bit signal, its decimal output is 240.
A based integer literal such as 8'hF0, without an s marker, is unsigned. A plain decimal integer literal such as 240 is signed and has a width of at least 32 bits. This course writes circuit-data literals with explicit widths so readers can check them easily. That is a design convention; it does not make every unsized literal illegal. An optional experiment below measures the widths used by our simulator.
Keeping eight bits discards information
The path to the display is eight bits wide, but the source may be wider. Suppose the source grows to nine bits and supplies 9'h1F0. The full pattern is 1_1111_0000, representing 496 when unsigned. Assigning it to an eight-bit destination keeps the low eight bits and discards the extra high bit. The result is 1111_0000, or F0.[1]
logic [8:0] source9;
logic [7:0] narrow;
initial begin
source9 = 9'h1F0;
narrow = source9;
$display("source=%0d narrow=%0d", source9, narrow);
end
A receiver that sees only F0 cannot reconstruct whether the source was 0F0 or 1F0. Both leave the same low eight bits. Truncation can be part of a valid specification when those are the only bits required. If all nine bits belong to the measurement, the interface needs a wider destination or a stated policy for values outside its range.
Check where truncation happens, too. Writing 8'h1F0 makes the literal itself eight bits wide. Its extra high bit is discarded while forming that literal. Assigning the result to sixteen bits later cannot recover the missing bit. Our main example uses an explicit nine-bit source so the loss at the destination is visible.
How can the same F0 mean minus sixteen?
For an unsigned eight-bit value, the position weights from right to left are 1, 2, 4, 8, 16, 32, 64 and 128. The high four bits of F0 are set, giving 128 + 64 + 32 + 16 = 240.
If the interface specifies signed two’s complement, the highest position instead has a weight of −128. The other seven weights stay positive. Reading the same set bits now gives −128 + 64 + 32 + 16 = −16. No bits were inverted. The interface still carries 1111_0000; the numerical definition has changed. A sensor’s interface specification or data sheet must tell the receiver which format it uses.
raw = 8'hF0;
$display("u bits=%08b decimal=%0d", raw, raw);
$display("s bits=%08b decimal=%0d", $signed(raw), $signed(raw));
The system function $signed(raw) treats this eight-bit value as signed while retaining its width and bit pattern. Both lines print identical binary digits. Their decimal outputs are 240 and −16. A signed signal declaration can also express the intended numerical format in a complete design.
There are still only 256 eight-bit patterns. Unsigned values range from 0 through 255; two’s complement ranges from −128 through 127. The 128 patterns with a zero high bit include zero and 127 positive integers. The other half represents −128 through −1. Zero uses one pattern in the nonnegative half, explaining the asymmetric endpoints. The highest bit is not a separate sign attached to an independent seven-bit magnitude.
Change one bit, read two values
Toggle each bit between zero and one. Both readings appear together; choosing an interpretation does not change the bits. This is a numerical concept model, not a Verilog simulator.
11110000 / F0: unsigned 240; eight-bit two’s complement −16.
- Binary
- 11110000
- Hexadecimal
- F0
- Unsigned
- 240
- Signed two’s complement
- −16
Widen to sixteen bits (shown as hexadecimal patterns):
Unsigned source, zero extension: 00F0
Signed source, sign extension: FFF0
Nine-bit source 0F0 (240) leaves low eight bits F0 (240).
Four-bit mode places the current pattern in the low bits of the nine-bit source too. Return to eight bits to revisit 1F0 → F0.
Widening follows the right-hand expression
Suppose the next interface grows to sixteen bits. To preserve an eight-bit signed −16, sign extension copies its high bit into the new positions. Adding eight ones to the left of F0 gives FFF0, which still reads as −16 in sixteen-bit two’s complement. An unsigned 240 needs zero extension instead: 00F0 preserves 240.
logic signed [7:0] sample;
logic [15:0] wide;
initial begin
sample = 8'shF0;
wide = sample; // FFF0: the signed RHS is sign-extended
wide = sample[7:0]; // 00F0: a part-select is unsigned
end
The destination wide is deliberately unsigned here. It makes the rule easier to see: the right-hand expression determines whether the assignment extends with zeros or copies the sign bit. The first assignment uses signed sample directly. The second uses a part-select, which is unsigned even though it covers the entire eight-bit vector.[1]
If the receiver expects a signed sixteen-bit measurement, the first version supplies −16 and the second supplies 240. A check of only the low eight bits would miss the difference. Checking the complete interface value exposes it. The repair keeps the signed source expression or makes the intended conversion explicit. The download tests all 256 inputs so the wrong version has to fail a real testbench.
Read the declaration together with its driver
The selector was written with wire. The widening example then used logic and logic signed. To understand how these signals behave, read each declaration together with its driver. wire declares a net whose value follows its drivers. Lesson one used a continuous assign to drive that connection. logic is a four-state data type that can declare a variable. SystemVerilog also allows a single continuous assignment to drive such a variable. Changing a type name does not replace checking who drives the signal.[1]
Older Verilog commonly uses reg for a variable assigned by a procedure. Both branches below assign an output, describing a combinational selector. Lesson F04 will develop complete-branch behavior in detail. For now, notice that both choices have a defined data source.
output reg [7:0] selected_o;
always @* begin
if (sel_i) selected_o = b_i;
else selected_o = a_i;
end
Running this version through Yosys produces one eight-bit $mux with no register or latch cells. The name reg does not make it retain a previous sample. Storage follows from the described behavior. Clocked registers arrive in F07.[3]
This series assigns a clear, single driving responsibility to each combinational output. Net resolution and variable-driver rules are different; an optional experiment demonstrates a conflict without making it part of our design style. Also distinguish initialization from a continuing connection: logic v = expression; initializes the variable. A separate assign v = expression; describes a continuous relationship.[1]
Where to look when simulation shows X or Z
At the start of a testbench, an uninitialized four-state logic variable can show X. It means the simulator cannot determine a logic value. An undriven wire shows Z in this experiment, representing high impedance. A real tri-state output also uses high impedance when it stops driving. What the connected line ultimately does depends on its other drivers and circuit conditions.[1]
logic [7:0] uninitialized;
wire [7:0] undriven;
initial begin
#1;
$display("logic=%08b wire=%08b", uninitialized, undriven);
end
Icarus Verilog 12.0 prints logic=xxxxxxxx wire=zzzzzzzz for this experiment. X is an unknown marker in the model, not a fixed third voltage on a chip. Start by checking whether the testbench initialized its inputs, then follow the drivers and connections. Analog voltages and metastability require separate physical models and analysis; this experiment does not measure them.
The two-state type bit cannot retain X or Z. Our uninitialized bit [7:0] prints zero. Making X disappear by switching to a two-state type does not establish that an initialization bug has been repaired. The testbench uses !== to check complete four-state results so an unknown cannot quietly pass a binary-only success check. The next lesson explains these comparison operators further.
Leave a signal contract someone else can check
An engineer reading F0 needs a format agreement before deciding whether the display should show 240 or −16. A useful interface table records the width, numerical format and driver. The mux rows below describe raw-bit transport; the source and receiver must still agree on the format. The sample_i and wide_o rows define the signed interpretation for the separate widening experiment. None of this lesson’s signals has a clocked sampling or storage requirement. If a later version must retain a sample, its contract will also need an update event.
| Signal | Width | Value or purpose | Driver |
|---|---|---|---|
a_i, b_i | 8 bits each | Raw patterns at this mux interface; confirm the format before reading a measurement | External source or testbench |
sel_i | 1 bit | 0 selects A, 1 selects B | Controller or testbench |
selected_o | 8 bits | The chosen source’s complete eight-bit pattern | Continuous assign |
sample_i | 8 signed bits | Two’s complement measurement in the widening experiment | External source or testbench |
wide_o | 16 bits | Sign-extended pattern, read as signed by the receiver | Widening module |
Download and test every pattern
Icarus Verilog 12.0 checked 256 numeric views, 512 truncations, 32 mux cases and the four-state probes. Correct widening passed all 256 inputs; the planted bug failed 128. Yosys 0.33 produced one eight-bit $mux for each selector form. Sign extension became wiring, with no storage cells.
Download RTL, testbenches and run instructions (ZIP)
File hashes and tool results
Actual run log
Run with Bash, Python 3, Icarus Verilog 12.0 and Yosys 0.33 on Ubuntu 24.04/WSL. The README gives setup and rerun instructions. These tests do not measure a physical circuit.
The package saves the simulator’s outputs and checks them with an independent mathematical program. It verifies both readings of all 256 eight-bit patterns and truncation for all 512 nine-bit inputs. The correct widening design passes every input. The planted bug fails 128 inputs, precisely the half that originally represents negative values.
Synthesis covers only the synthesizable selector and widening modules. X/Z probes, printed output and input enumeration are simulation observations. They do not constitute measurements of a physical circuit. The browser inspector is a conceptual model as well; download the source to check the RTL itself.
Check your understanding with five questions
Repeat the reasoning with four bits
Put 1111 in a four-bit signal and read it as unsigned and as two’s complement. Widen it to eight bits using zero extension and sign extension. What changes if a full-width part-select replaces the original signed source?
Reference answer
The unsigned value is 15. In four-bit two's complement, the high position weighs −8, giving −8+4+2+1=−1. Zero extension produces 0000_1111. Keeping the signed source produces 1111_1111, still −1 in eight-bit two's complement. A full-width part-select is unsigned, so widening it instead gives 0000_1111. Four-bit signed values range from −8 through 7.
Extension: measuring unsized literals
The supplied value_views.sv measures $bits(240)=32, $bits('hF0)=32, $bits(8'hF0)=8 and $bits('shF0)=32 with Icarus 12.0. The standard requires at least 32 bits for ordinary unsized integer literals; these observations do not make every unsized form exactly 32 bits. Plain decimal and based literals with s are signed. A based literal without s is unsigned. The fill literal '1 is a separate form, with a self-determined $bits value of 1; its behavior in a destination context differs from ordinary decimal 1. Mixed arithmetic and expression widths are left for F05.[1]
Extension: conflicting drivers on one wire
four_state.sv drives one wire continuously with both zero and one at the same default strength. Icarus 12.0 resolves it to X. This is a net-model result. A real output conflict is not an acceptable third numerical value, and the permission to resolve multiple net drivers does not apply to a logic variable. The example is simulated only, with no synthesis or board experiment.
The display pattern 1111_0000 can now be described by its width, by the reading the interface requires (240 unsigned, or −16 in two’s complement), and by its driver. You can also explain how truncation can discard a high bit, or how a part-select drops the source’s signed interpretation. The next lesson uses these bits in Boolean conditions and compares the questions answered by &, &&, ~ and !.
Sources and further reading
- IEEE Std 1800-2017: §5.7.1 integer literals, §6.3 four-state values, §6.5–6.6 nets and drivers, §6.11 integer types, §11.5.1 selects and §11.8 expression conversion. Standard PDF hosted by an MIT course. This lesson checks that edition, without claiming a review of the complete 2023 edition.
- Tools and style: Icarus language flags, Yosys Verilog support and the lowRISC Verilog style guide. Experiments pin Icarus 12.0 and Yosys 0.33. A style recommendation and a language requirement are different kinds of guidance.