I have a vector signal tmp : std_logic_vector(15 downto 0)
I have to shift it to left or right of n bit. how can I realize this operation. I thought to concatenation operation but I didn’t know how use it.
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Use the
ieee.numeric_stdlibrary, and the appropriate vector type for the numbers you are working on (unsignedorsigned).Then the operators are `sla`/`sra` for arithmetic shifts (ie fill with sign bit on right shifts and lsb on left shifts) and `sll`/`srl` for logical shifts (ie fill with ‘0’s).
You pass a parameter to the operator to define the number of bits to shift:
—
Update:
—
I have no idea what I was writing above (thanks to Val for pointing that out!)
Of course the correct way to shift
signedandunsignedtypes is with theshift_leftandshift_rightfunctions defined inieee.numeric_std.The shift and rotate operators
sll,roretc are for vectors ofboolean,bitorstd_ulogic, and can have interestingly unexpected behaviour in that the arithmetic shifts duplicate the end-bit even when shifting left.And much more history can be found here:
http://jdebp.eu./FGA/bit-shifts-in-vhdl.html
However, the answer to the original question is still