Literals, vectors, and operators
Write unambiguous constants, manipulate bits, and avoid width and signedness pitfalls.
Giving constants a width
A Verilog constant can specify its width, base, and value:
8'b1010_0110
8'hA6
8'd166
12'o245These items do not all have the same width: the first three occupy 8 bits, while the last one occupies 12 bits. Underscores improve readability without changing the value.
The general form is width'basevalue. Common bases are b for binary, o for octal, d for decimal, and h for hexadecimal.
An unsized constant such as 5 follows implicit rules that can widen an expression or change its signed interpretation. In RTL, writing 4'd5 or 8'd5 makes the intent clearer.
Vectors and bit selection
wire [