Issue with sort() function of queue/array

Hi,

In my verif env I am trying something as follows(I can’t share code so wrote this dummy code)

module test3;

int q[$]={32'h1,32'h2,32'h4,32'h8,32'h10000000,32'h20000000,32'h40000000,32'h80000000};
initial begin
q.sort();
foreach(q[i])
$display("data=%h",q[i]);
end
endmodule

As per my understanding sort function should arrange variables of queue in ascending order. But this is what the output is:
data=80000000
data=00000001
data=00000002
data=00000004
data=00000008
data=10000000
data=20000000
data=40000000
So I see that q[0] is always 80000000 while I expect it to be at q[7] here. Please let me know why?

int is defined as “2-state data type, 32-bit signed integer” in the IEEE Std 1800-2012 (Section 6.11 “Integer data types”). I think 32’h80000000 is interpreted as a negative number, and it is therefore smaller than 1, 2, 4 etc.

You could use an unsigned data type:

bit [31:0] q[$] = {32'h1, 32'h2, 32'h4, 32'h8, 32'h10000000, 32'h20000000, 32'h80000000};