I need to convert a dynamic array of ints to a dynamic array of bytes, in the right order:
The first byte should be the least significant bits of the first integer. I wanted to do this using the streaming operator, but this seems to reverse either the int order or the byte-in-int order:
int unsigned int_data[]=new[3];
byte unsigned byte_data[];
int_data[0]=0;
int_data[1]=1;
int_data[2]=2;
byte_data={<<byte{int_data}};
foreach(byte_data[z]) begin
$display(" %0d",byte_data[z]);
end
This prints:
2
0
0
0
1
0
0
0
0
0
0
0
So the order of the ints is wrong. I really need it to be:
0
0
0
0
1
0
0
0
2
0
0
0
Using >> gets the int order right, but the byte order wrong.
I tried some things using the ‘with’ extension, but can’t figure out how to use it.