Keysymbols: >>, <<.
The shift operators are shift left and shift right. The shift operator takes a vector and a number indicating the shift. The empty bits caused by shifting are filled with zeros. See examples below.
module shiftTest;
reg [3:0] a;
initial begin
a = 4'b1010;
$displayb(a << 1); // shift left by 1, evaluates to 4'b0100
$displayb(a >> 2); // shift right by 2, evaluates to 4'b0010
end
endmodule // shiftTest
This operator is useful in modelling shift registers, long multiplication algorithms, etc.
EXERCISE
What does the following evaluate to ?
$displayb((4'b0110 == (4'b1100 >> 1)));
$displayb((4'b0110 == (4'b1100 << 1)));