That was a limitation in the constraint if a number is starting with zeros. The below logic works fine with all combinations.
class A;
rand bit [23:0]AA;
constraint AA_C {
if(AA[23] == 0)
($countones(AA ^ (AA>>1))) == 16;
else
($countones(AA ^ (AA>>1))-1) == 16;
}
endclass
In reply to mayurkubavat: