I am trying to come up with an expression to reverse the bytes of a 32 bit Integer.
Below code seems to work but I don’t understand it especially the line k = {<<{bitq}}
. I try to read the number, left to right in a bit[3:0] queue. I reverse the order of the bytes in queue and somehow the line above results in each byte of the int reversed. Can someone please explain how does the streaming operator work in this case
module tb;
int k;
// Reverse of A is 5, B is D, C is 3 and D is B
// Reverse of ABCD is 5D3B, we want k to be byte reversed so
// answer should be k = 32'h5d3b5d3b
bit[3:0] bitq[$];
int x;
initial begin
k = 32'hABCDABCD;
bitq = {>>4{{k}}};
$displayh("%p",bitq);
bitq = {<<4{bitq}};
$displayh("%p",bitq);
k = {<<{bitq}};
$displayh("%h",k);
end
endmodule