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 to integer or double a std_logicc_vector of 40 bits in VHDL

Status
Not open for further replies.

kalyansrinivas

Advanced Member level 4
Joined
Jul 7, 2007
Messages
100
Helped
5
Reputation
10
Reaction score
4
Trophy points
1,298
Activity points
1,910
How to convert a std_logic_vector of 40 bits to integer or double in VHDL

Dear Friends

In VHDL we have conv_integer to convert a std_logic_vector of less than 32 bits to integer

But i have a output result of more than 32 bits (40-bits- std_logic_vector ) and i want it to be as an integer or as a double to be printed out to a text file

Please resolve my issue How to convert a standard logic vector of more than 32 bits to be printed as integer or double to a output text file

Regards
M Kalyansrinivas
 
Last edited:

first of all, conv_integer is not part of any IEEE standard code libraries. Std_logic_vectors should NOT be used as numbers. You should use the signed and unsigned types from the numeric_std library.

Secondly, to answer your question - you cannot use integers more than 32 bits. But you can output std_logic_vectors directly using the std_logic_textio package in binary (read/write), octal (oread/owrite) and hex (hread/hwrite).

If you have to output it as a base 10 number, you'll have to write a clever conversion function.
 

Re: How to convert to integer or double a std_logic_vector of 40 bits in VHDL

Thank you very much

If i write a logic for converting the 40 bit vector to a base 10 value in vhdl then the output result should be of certain data type (as data type integer will hold only -2^32 to + 2^32) .Can you tell me what data type should i declare for holding this value

Regarding signed and unsigned should be used only in testbenches or also in the synthesizable code as we have std_logic_vector takes care of every thing(2's complement format)

Regards
M Kalyansrinivas
 
Last edited:

There is no data type to hold it. You'll have to write some clever function that converters the 40 bit number into two integers.

---------- Post added at 08:24 ---------- Previous post was at 08:23 ----------

Signed and unsigned are perfectly synthesisable. The weakness with std_logic_vector is you cannot do signed and unsigned in the same file.
 

I'm not sure what converting to a base 10 datatype means. Internally, all data are binary. The problem is output outputting a decimal number. You can use binary coded decimal as an intermediate result when converting the binary bit vector. It's simply a bit vector of 4*number of digits length, that can in fact hold the intended decimal representation of the number. Each 4 bit subvector represents one decimal digit.

For a conversion routine that doesn't rely on constrained integer, you can refer to double dabble algorithm Double dabble - Wikipedia, the free encyclopedia
 

The problem is writing the data to a text file in base 10. For string types (std_logic_vector etc) there only exist functions to write to a text file in binary, octal or hex. The only thing that will print out in base 10 are integers (the default write function) or a string. So you either have to get clever with integers, or write a base 10 std_logic_vector to string converter. neither will be trivial.
 

Status
Not open for further replies.

Part and Inventory Search

Welcome to EDABoard.com

Sponsor

Back
Top