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:
          int_add_out <= conv_integer(unsigned(addout(15 downto 0)));

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  
 
 [ 3 post ] 

 Relevant Pages 

1. newbie Q: converting INTEGER to BIT_VECTOR?

2. conversion integer to bit_vector

3. Type conversion from integer to bit_vector

4. How to convert an integervariable to bit_vector?

5. convert bit_vector to std_logic_vector

6. CONVERT BIT_VECTOR TO INT AND VICE VERSA

7. converting large integer to smaller seed

8. converting login name to an integer

9. Converting a number in a String character to an Integer

10. Converting DOS INTEGER to Clarion DECIMAL

11. Converting Integer at Table, into Date at Form level

12. Converting integer to date field

 

 
Powered by phpBB® Forum Software