Lets take example of bits (unsigned) and byte (signed) data type.
8 bit packed array of bit : bit [7:0] a (0 to 255)
byte b (-128 to 127)
Binary Represantation: c 11111111 d 11111111 bit_sum1 11111110 bit_sum2 11111110 byte_sum1 11111110 byte_sum2 11111110
Decimal Represantation: c 255 d -1 bit_sum1 254 bit_sum2 254 byte_sum1 -2 byte_sum2 -2
8 bit packed array of bit : bit [7:0] a (0 to 255)
byte b (-128 to 127)
module test(); bit[7:0] a=2'h00,b=2'h01,c,bit_sum1,bit_sum2; byte d,byte_sum1,byte_sum2; initial begin c = a-b; d = a-b; bit_sum1 = c - 1; bit_sum2 = d -1; byte_sum1 = c -1; byte_sum2 = d - 1; $display("Binary Representation : %b d %b bit_sum1 %b bit_sum2 %b byte_sum1 %b byte_sum2 %b",c,d,bit_sum1,bit_sum2,byte_sum1,byte_sum2); $display("Decimal Representation : c %0d d %0d bit_sum1 %0d bit_sum2 %0d byte_sum1 %0d byte_sum2 %0d",c,d,bit_sum1,bit_sum2,byte_sum1,byte_sum2); end endmoduleOutput :
Binary Represantation: c 11111111 d 11111111 bit_sum1 11111110 bit_sum2 11111110 byte_sum1 11111110 byte_sum2 11111110
Decimal Represantation: c 255 d -1 bit_sum1 254 bit_sum2 254 byte_sum1 -2 byte_sum2 -2
No comments:
Post a Comment