i have a verilog code in which there is a line as follows:
parameter ADDR_WIDTH = 8 ;
parameter RAM_DEPTH = 1 << ADDR_WIDTH;
here what will be stored in RAM_DEPTH
and what does the <<
operator do here.
i have a verilog code in which there is a line as follows:
parameter ADDR_WIDTH = 8 ;
parameter RAM_DEPTH = 1 << ADDR_WIDTH;
here what will be stored in RAM_DEPTH
and what does the <<
operator do here.
<<
is the left-shift operator, as it is in many other languages.Here
RAM_DEPTH
will be1
left-shifted by8 bits
, which is equivalent to2^8
, or256
.<<
is a binary shift, shifting 1 to the left 8 places.>>
is a binary right shift adding 0's to the MSB.>>>
is a signed shift which maintains the value of the MSB if the left input is signed.Three ways to indicate left operand is signed:
1 << ADDR_WIDTH
means 1 will be shifted 8 bits to the left and will be assigned as the value forRAM_DEPTH
.In addition,
1 << ADDR_WIDTH
also means 2^ADDR_WIDTH.Given
ADDR_WIDTH = 8
, then2^8 = 256
and that will be the value forRAM_DEPTH