Convert bit_vector to integer
Author Message
Convert bit_vector to integer

Hi folks,

I am looking for an easy way to convert a std_logic_vector or a
bit_vector value to an integer value.

I am using Synopsys. Is there any predefined function for that ?

Thanks for any info.

Alex

Mon, 17 Apr 2000 03:00:00 GMT
Convert bit_vector to integer

Quote:

>      I am looking for an easy way to convert a std_logic_vector or a
> bit_vector value to an integer value.

> I am using Synopsys. Is there any predefined function for that ?

Just look into the online docs about the IEEE.std_logic_arith package.
There you can find a couple of type conversion functions.

In your case something like the following might do the job:

Joe

--
Josef Fleischmann       http://www.regent.e-technik.tu-muenchen.de/~jsf
Institute of Electronic Design Automation
Technical University of Munich, 80290 Munich, Germany

Tue, 18 Apr 2000 03:00:00 GMT
Convert bit_vector to integer

Quote:

> Hi folks,

>      I am looking for an easy way to convert a std_logic_vector or a
> bit_vector value to an integer value.

> I am using Synopsys. Is there any predefined function for that ?

> Thanks for any info.

>      Alex

Here are some functions to go both ways.

------------------------------------------------------------------------

-------------------------------------------------------------------------

--
-- Covert standard logic vector to integer
--

FUNCTION slvect2int(vect : std_logic_vector) RETURN INTEGER IS

VARIABLE size :   INTEGER RANGE vect'length-1 DOWNTO 0;
VARIABLE result : INTEGER RANGE (2**size)-1 DOWNTO 0;
BEGIN
result := 0;
FOR i IN 0 TO size LOOP

IF (vect(i) = '1') THEN
result := result + 2**i;
END IF;

END LOOP;
RETURN result;
END slvect2int;

-------------------------------------------------------------------------

-------------------------------------------------------------------------

--
-- Convert integer to standard logic vector
--

FUNCTION int2slvect(int_value : INTEGER; size:  INTEGER) RETURN
std_logic_vector IS

VARIABLE result : std_logic_vector(size-1 DOWNTO 0);
BEGIN
FOR i IN 0 TO size LOOP

IF ((int_value/(2**i)) REM 2) = 0 THEN
result(i) := '0';
ELSE
result(i) := '1';
END IF;
END LOOP;
RETURN result;
END int2slvect;

-------------------------------------------------------------------------

--
__/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/

Richard Schwarz, President              EDA & Engineering Tools
Associated Professional Systems (APS)   http://www.associatedpro.com

Abingdon, Maryland 21009
Phone: 410.569.5897                     Fax:410.661.2760

__/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/ __/

Wed, 19 Apr 2000 03:00:00 GMT

 Page 1 of 1 [ 3 post ]

Relevant Pages