Home / Learn Verilog / Number Literals in Detail

Number Literals in Detail

Sized, unsized, signed and underscores.

Quick summarySized, unsized, signed and underscores.

How to think about this

Literal forms8'hFF sized hex'd10 unsized (32-bit)-8'sd5 signed16'b1010_1111_0000_0101
Literal forms

Definition

Format: size, apostrophe, base, digits. 4'b1010, 8'hFF, 12'd300, 'o17.

Why you need this

Wrong sizes cause silent truncation or extension.

How it works

Always size constants that go into a bus.

Where you'll see this

  • Everyday RTL design
  • FPGA and ASIC projects
  • Testbenches and debugging

Try it

Truncation and extensionVerilog: edit and run

Extra high bits are dropped; missing high bits are 0.

Test what you just read

1. 12'd300 has how many bits?