Menu
Coddy logo textTech

Unsized Numbers

Part of the Fundamentals section of Coddy's Verilog journey — lesson 15 of 90.

An unsized number is a number written without specifying how many bits it has. When you write a number without a size prefix, Verilog assumes it is 32 bits by default.

a = 'b1010;        // Unsized: Verilog treats this as 32 bits
a = 32'b1010;    // Same as above, but explicit

Unsized numbers use only the format and value: [format][value]

  • <strong>format</strong> — the base of the number: b for binary, d for decimal, h for hexadecimal, or o for octal
  • <strong>value</strong> — the actual number (for example, 1010)

The apostrophe ' is still required between the format and value, but there is no bit count before it.

  • 'b1010 — 32-bit binary 1010
  • 'd255 — 32-bit decimal 255
  • 'hFF — 32-bit hex FF
  • 'b1 — 32-bit binary 1 (with 31 leading zeros)

Code Example:

reg [7:0] data;

initial begin
  data = 1010;      // Unsized: 32-bit value (may cause warning)
  data = 'd255;     // Unsized: 32-bit decimal 255
  data = 'hFF;      // Unsized: 32-bit hex FF
end

Unsized vs Sized

 UnsizedSized
Example1010 or 'd2558'b1010 or 8'd255
Bit width32 bits (default)Explicit (as specified)
ApostropheRequired with formatRequired
When to useSimple testbench codeHardware assignments

Potential Problem

Unsized numbers can cause unexpected behavior when assigned to smaller registers:

reg [3:0] small;
small = 'b1111;      // 32-bit value, but fits in 4 bits (fine)
small = 'b10000;     // 32-bit value, but too large! (warning)

The second example assigns a 32-bit value 10000 to a 4-bit register. Only the lower 4 bits are kept (0000), which may not be what you expect.

When to Use Unsized Numbers

Unsized numbers are convenient for:

  • Simple numbers in testbenches
  • Loop counters
  • $display statements

For actual hardware assignments, use sized numbers to be explicit and avoid warnings.

challenge icon

Challenge

In the code below, some numbers are unsized. Change them to sized numbers (8 bits) to avoid warnings.

What to do:

  1. Change a to an 8-bit binary number for 1010
  2. Change b to an 8-bit decimal number for 255
  3. Change c to an 8-bit hex number for FF

Cheat sheet

Unsized numbers in Verilog default to 32 bits. Syntax: '[format][value]

'b1010   // 32-bit binary
'd255    // 32-bit decimal
'hFF     // 32-bit hex

Sized numbers use [bits]'[format][value]:

8'b1010  // 8-bit binary
8'd255   // 8-bit decimal
8'hFF    // 8-bit hex

Assigning an unsized number to a smaller register keeps only the lower bits — use sized numbers for hardware assignments to avoid warnings and unexpected truncation.

Try it yourself

module unsized_challenge;
  reg [7:0] a, b, c;
  
  initial begin
    a = 'b1010;      // Change to sized (8-bit binary)
    b = 'd255;     // Change to sized (8-bit decimal)
    c = 'hFF;      // Change to sized (8-bit hex)
    
    $display("a = %b", a);
    $display("b = %b", b);
    $display("c = %b", c);
    $finish;
  end
endmodule
quiz iconTest yourself

This lesson includes a short quiz. Start the lesson to answer it and track your progress.

All lessons in Fundamentals