rule of thumb * R! F( x# p% K7 m7 f0 k7 u' i" F e9 r
1 l5 q0 ?9 {" x A, E$ |5 t8 P7 O" {
The format of the signed type is two’s complement. 有符号数均为补码表示
If any operand in an expression is unsigned the operation is considered to be unsigned. 只有计算表达式右边有无符号数,整个计算式都按照无符号数规则运算
只有算式右边全为有符号数,运算才会自动补齐所需的bit数,n+n=n+1.n*n=2n
The value -4 represented as a 3bit signed hex value would be specified as -3’sh4. A decimal number is always signed. verilog2001中用’s来特别声明有符号数,十进制的数都是有符号数
Type casting using $unsigned will make the operation unsigned. The operand will be sign extended with 0’s if necessary. $usigned()函数在高位补0
A=$signed(B) will extend using sign bit. $unsigned()函数会在高位补与符号位相同的bit7 x/ Y; c9 q' U& b
7 v+ o* Q! a# U3 e# W' H( W4 K4 H, Q
: O$ x$ t ^: i: q5 N' ?* X0 ~4 Ybasic signed addition$ l' i5 W2 G/ V( r) W# F6 O6 `
- @3 _2 B3 ]9 }" J: _5 u. z; x' ?