Continue to Site

Welcome to EDAboard.com

Welcome to our site! EDAboard.com is an international Electronics Discussion Forum focused on EDA software, circuits, schematics, books, theory, papers, asic, pld, 8051, DSP, Network, RF, Analog Design, PCB, Service Manuals... and a whole lot more! To participate you need to register. Registration is free. Click here to register now.

how to convert integer to bit_vector?

Status
Not open for further replies.

20vt

Newbie level 4
Newbie level 4
Joined
Jul 28, 2013
Messages
7
Helped
0
Reputation
0
Reaction score
0
Trophy points
1
Visit site
Activity points
42
I did a program that counts the ones on a number(6 length) like 011100 the out is 3
but I want the outpot to be in bit_victor (2 down to 0) and not integer
if I input this num 011100 the output should be '011' and not 3
 

Take a look at the attached help document about numeric_std.

As you can see, one conversion and one cast are necessary to go from integer to std_logic_vector:

std_logic_vector_signal <= std_logic_vector(to_unsigned(integer_result, std_logic_vector_signal'length));

However, if you don't want the result as integer, I recommend you to use type "unsigned". It is intended to represent a number, but you can do the same bit-manipulation as with std_logic_vector.
Then you only need the "to_unsigned" conversion.
 

Attachments

  • numeric_us_1785.pdf
    105.2 KB · Views: 136
  • Like
Reactions: 20vt

    20vt

    Points: 2
    Helpful Answer Positive Rating
LIBRARY ieee ;
USE ieee.std_logic_1164.all;
USE ieee.std_logic_arith.all;
use IEEE.numeric_std.all;

entity conterone is
port(d:in bit_vector(6 downto 0);
count:eek:ut integer

) ;
end conterone;

architecture arc_conterone of conterone is
signal x : unsigned (2 downto 0) ;


begin
process(d)
variable c:integer;
begin
c:=0;
for i in 0 to 6 loop
if(d(i)='1')then
c:=c+1;
end if;
end loop;
count <= c ;
x <= to_UNSIGNED (count,3);


end process;
end arc_conterone;

how to convert correctly ?
 

so how I do it?
if I remove this library it wont count
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top