top of page

4.4 Numbers Representation

Constant numbers are represented in two ways:

  • Integer Constants

  • Real Constants

 

4.4.1 Integer Constants

 

Integer constants can be specified in decimal, hexadecimal, octal, or binary format.

 

There are two forms to express integer constants which are given below:

 

A.  Unsized Number: Simple decimal number, a sequence of digits [0-9], optionally starting with a plus or minus unary operator.

e.g., 19091, +19382, -91289.

 

B.  Sized Number: Based constant, which shall be composed of up to three tokens.

  • an optional size constant, shall specify the size of the constant in terms of its exact number of bits.

  • an apostrophe character (', ASCII 0x27) followed by a base format character, shall consist of a case insensitive letter specifying the base for the number. Legal base specifications are d, D, h, H, o, O, b, or B, for the base’s decimal, hexadecimal, octal, and binary respectively. The apostrophe character and the base format character shall not be separated by any white space.

  • the digits representing the value of the number.

 

It shall be legal to macro substitute these three tokens.

 

Negative Constant Numbers

 

Simple decimal numbers without the size and the base format shall be treated as signed integers, whereas the numbers specified with the base format shall be treated as signed integers if the s designator is included or as unsigned integers if the base format only is used.

 

The s designator does not affect the bit pattern specified, only its interpretation.

 

A plus or minus operator preceding the size constant is a unary plus or minus operator.

e.g., -4 or +4

 

A plus or minus operator between the base format and the number is an illegal syntax.

  Verilog

  -4'd7 // Used for performing unsigned integer math, will be stored as 2's complement of 7

  -4'sd7 // Used for performing signed integer math

 

  4'd-7 // Illegal

Unsized Constant Numbers

 

Numbers specified without a base format are considered as decimal numbers by default. Numbers that are written without size are simulator/machine specific but must be at least 32 bits.​​​​​​​​​​​​

  Verilog

  659       // is a decimal number

  'h837FF   // is a hexadecimal number

  'o7460    // is an octal number

  4af       // is illegal (hexadecimal format requires 'h)

​Sized Constant Numbers

  Verilog

  4'b1001 // is a 4-bit binary number

  'D3     // is a 5-bit decimal number (Simulator/Machine Specific)

X or Z Values

  Verilog

  3'b01x // is a 3-bit number with the least significant bit unknown

  12'hx  // is a 12-bit unknown number

  16'hz  // is a 16-bit high-impedance number

  16'sd? // the same as 16'sbz

The default length of x and z is the same as the default length of an integer.

 

4.4.2 Real Constants

 

Real numbers are specified as given below:

  • decimal notation (e.g., 14.72)

  • scientific notation (e.g., 39e8)

  • scaled notation (e.g., 24.7K)

 

Real numbers expressed with a decimal point shall have at least one digit on each side of the decimal point.​​

 

 

Underscore Character

 

The underscore character is legal anywhere in an integer constant.

 

The underscore character is legal anywhere in a real constant except as the first character of the constant or the first character after the decimal point. The underscore character is ignored by the simulator.

  Verilog

  E.g., 16’b1011_1000_1111_1010 // Underscore increase the readability of a number constant

Operator Usage

String

© Copyright 2025 VLSI Mentor. All Rights Reserved.©

Connect with us

  • Instagram
  • Facebook
  • Twitter
  • LinkedIn
  • YouTube
bottom of page