Search code examples
vhdl

Two's complement VHDL


I am just trying to make a simple two's complement device in VHDL but it is throwing back this really annoying error and I'm unsure what I have done wrong. Probably something very silly...The error is "Error (10327): VHDL error at twocompliment.vhd(21): can't determine definition of operator ""nand"" -- found 0 possible definitions"

The code is

library ieee;
use ieee.std_logic_1164.all; 
use ieee.numeric_std.all;
entity twoscompliment is
      generic
      (
              Nbits : positive := 8 
       );
 port 
( 
           --Inputs
           A : in std_logic_vector (Nbits-1 downto 0);
           --Outputs
           Y : out std_logic_vector (Nbits downto 0)
);
end twoscompliment;

architecture twoscompliment_v1 of twoscompliment is
 begin
  Y <= std_logic_vector(unsigned(A NAND '1') + '1');
 end twoscompliment_v1;

Any help would be awesome!


Solution

  • Try this:

    architecture twoscompliment_v1 of twoscompliment is
    signal temp : std_logic_vector(Nbits-1 downto 0);
    begin
      temp <= not A;
      Y    <= std_logic_vector(unsigned(temp + 1));
    end twoscompliment_v1;