I have below code and I wonder if there is a simple way to implement it. (What I want is transfer the data in 8-bit array to the data with 32-bit array)
typedef byte unsigned uint8;
typedef int unsigned uint32;
function void 8to32(uint8 data_in[], ref uint32 data_out[]);
int size = data_in.size;
int left = size % 4;
data_out = new[size/4+1];
int j = 0;
for (int i = 0; i < size; i = i + 4) begin
data_out[j++] = {data_in[3+i], data_in[2+i], data_in[1+i], data_in[i]};
end
// how to simple below code ??
if (left == 1)
data_out[j] = {24'b0, data_in[size-1]};
else if (left == 2)
data_out[j] = {16'b0, data_in[size-1], data_in[size-2]};
else if (left == 3)
data_out[j] = {8'b0, data_in[size-1], data_in[size-2], data_in[size-3]};
endfunction : 8to32
Thank you !