module TB ;
bit bb [2] = '{ 1 , 0 } ;
initial begin
foreach( bb[i] )
begin
$display(" bb[%0d] is %0b ",i , bb[i] ) ;
$display(" int'( ( ~ bb[%0d] ) ) is %32b ",i , int'( ( ~ bb[i] ) ) ) ; // [ A ]
$display(" int'( ( ! bb[%0d] ) ) is %32b ",i , int'( ( ! bb[i] ) ) ) ; // [ B ]
$display(" int'( 1'( ~ ( bb[%0d] ) ) ) is %32b ",i,int'( 1'( ~ ( bb[i] ) ) ) ) ; // [ C ]
$display(" int'( ~ ( 1'( bb[%0d] ) ) ) is %32b ",i,int'( ~ ( 1'( bb[i] ) ) ) ) ; // [ D ]
$display("==============================================================") ;
end
end
endmodule
The output I Observe ::
**bb[0] is 1
int’( ( ~ bb[0] ) ) is 11111111111111111111111111111110
int’( ( ! bb[0] ) ) is 00000000000000000000000000000000
int’( 1’( ~ ( bb[0] ) ) ) is 00000000000000000000000000000000
int’( ~ ( 1’( bb[0] ) ) ) is 11111111111111111111111111111110
bb[1] is 0
int’( ( ~ bb[1] ) ) is 11111111111111111111111111111111
int’( ( ! bb[1] ) ) is 00000000000000000000000000000001
int’( 1’( ~ ( bb[1] ) ) ) is 00000000000000000000000000000001
int’( ~ ( 1’( bb[1] ) ) ) is 11111111111111111111111111111111
==============================================================**
For first two expressions , first due to the int’() Cast , the size of the expression is 32-bits and then expressions resolve to ::
( ~ 32’h0000_0001 ) and ( ! 32’h0000_0001 ) . Hence the 1st two output is as per expectation .
However I am not sure about how [C] and [D] are resolved
Why does the Output differ between [C] and [D] ?