0

In VHDL I want to take a 14 bit input and append '00' on the end to give me a 16 bit number which is the 14 bit input multiplied by 4 and then put this into a 17 bit signed variable such that it is positive (the input is always positive). How should I go about this?

like this? shiftedInput <= to_signed('0' & input & '00', 17);

Or maybe like this? shiftedInput <= to_signed(input sll 2, 17);

Or this? shiftedInput <= to_signed(input & '00', 17);

Does it see that the std_logic_vector it's getting is 16 bit and the signed variable is 17 bit and therefore assume the most significant bit (the singing bit) is 0?

Or do I have to do this? shiftedInput <= to_signed('0' & input sll 2, 17);

e.g. If I read in the 14 bit number 17 as a std_logic_vector [i.e. (00 0000 0001 0001)] it should be converted to the signed number +68. [i.e. (0 0000 0000 0100 0100)]

3
  • What is the type of input? What errors do you encounter with your various attempts? Commented Aug 21, 2016 at 16:22
  • input is a std_logic_vector(13 downto 0) Commented Aug 21, 2016 at 16:57
  • 1st option gives: no function declarations for operator "&" 2nd option gives: no function declarations for operator "sll" 3rd option gives: prefix is neither a function name nor can it be sliced or indexed 4th option gives: no function declarations for operator "sll" Commented Aug 21, 2016 at 17:05

1 Answer 1

3

std_logic_vector is compatible with the type signed of numeric_std. So, the type conversion function is signed (not to_signed that converts between integers and vectors):

shiftedInput <= signed('0' & input & "00"); 

should make it. Note the "00" instead of your '00'. Bit strings are double-quoted while bits are single-quoted.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.