Integers can be in binary (
b
or
B
), decimal (
d
or
D
), hexidecimal (
h
or
H
) or octal (
o
or
O
).
Numbers are specified by
1. <size>'<base><number> : for a full description
2. <base><number> : this is given a default size which is machine
dependant but at least 32 bits.
3. <number> : this is given a default base of decimal
The size specifies the exact number of bits used by the number. For
example, a 4 bit binary will have 4 as the size specification and a 4
digit hexadecimal will have 16 as the size specification since each
hexadecimal digit requires 4 bits.
8'b10100010 // 8 bit number in binary representation 8'hA2 // 8 bit number in hexadecimal representation
x represents an unknown, and z a high impedance value. An x declares 4 unknown bits in hexadecimal, 3 in octal and 1 in binary. z declares high impedance values similarly. Alternatively z, when used in numbers, can be written as ? This is advised in case expressions to enhance readability.
4'b10x0 // 4 bit binary with 2nd least sig. fig. unknown 4'b101z // 4 bit binary with least sig. fig. of high impededamce 12'dz // 12 bit decimal high impedance number 12'd? // 12 bit decimal high impedance 'don't-care' number 8'h4x // 8 bit number in hexidecimal representation with the // four least significant bits unknown
A number can be declared to be negative by putting a minus sign infront of the size. The minus sign must appear at the start of a number (in all three formats given above), ie. it must not appear between the size specifier and base, nor between the base and the format specidications.
-8'd5 // 2's compliment of 5, held in 8 bits 8'b-5 // illegal syntax
Underscores can be put anywhere in a number, except the beginning, to improve readability.
16'b0001_1010_1000_1111 // use of underscore to improve readability 8'b_0001_1010 // illegal use of underscore
Real numbers can be in either decimal or scientific format, if expressed in decimal format they must have at least one digit either side of the decimal point.
1.8 3_2387.3398_3047 3.8e10 // e or E for exponent 2.1e-9 3. // illegal