A
Adam
Guest
Hello,
I'm trying to code a module to do the following algorithm:
If Input is even, divide by 2 and do two's complement(invert bits and add 1)
If Input is odd, increment by 1 and then divide by 2.
No matter what types I use, I can't seem to use any operators( /, srl, not).
I usually get 'can not have such operands in this context' errors. Input is
defined as std_logic_vector(7 downto 0) and SignNum is unsigned(7 downto 0).
Both are signals. I can get around not using the shift/divide operators,
but not the negation. What data type should I use to be able to use 'not'?
Am I going about this problem the correct way? Thanks.
SignedCalc : process(Input)
variable EvenShift : unsigned(7 downto 0);
variable OddShift : unsigned(7 downto 0);
variable OddInc : unsigned(7 downto 0);
variable uInput : unsigned(7 downto 0);
begin
uInput := unsigned(Input);
if(Input(0) = '0') then --Even number
EvenShift := "0" & uInput(7 downto 1);
SignedNum <= (not EvenShift) + 1;
else --Odd Number
OddInc := uInput + 1;
OddShift := "0" & OddInc(7 downto 1);
SignedNum <= OddShift;
end if;
end process;
I'm trying to code a module to do the following algorithm:
If Input is even, divide by 2 and do two's complement(invert bits and add 1)
If Input is odd, increment by 1 and then divide by 2.
No matter what types I use, I can't seem to use any operators( /, srl, not).
I usually get 'can not have such operands in this context' errors. Input is
defined as std_logic_vector(7 downto 0) and SignNum is unsigned(7 downto 0).
Both are signals. I can get around not using the shift/divide operators,
but not the negation. What data type should I use to be able to use 'not'?
Am I going about this problem the correct way? Thanks.
SignedCalc : process(Input)
variable EvenShift : unsigned(7 downto 0);
variable OddShift : unsigned(7 downto 0);
variable OddInc : unsigned(7 downto 0);
variable uInput : unsigned(7 downto 0);
begin
uInput := unsigned(Input);
if(Input(0) = '0') then --Even number
EvenShift := "0" & uInput(7 downto 1);
SignedNum <= (not EvenShift) + 1;
else --Odd Number
OddInc := uInput + 1;
OddShift := "0" & OddInc(7 downto 1);
SignedNum <= OddShift;
end if;
end process;