Type Conversion of an Array of Integer to Signed
If I Have an Array of Like Defined Below. .. Type A_Type Is Array (0 to 9) of Integer; Signal My_Array: A_Type: = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9); If Later Down...
If I have an array of like defined below...
type A_type is array (0 to 9) of integer;
signal my_array : A_type := (0, 1, 2, 3, 4, 5, 6, 7, 8, 9);
If later down the line I want to convert to a list of signed numbers representing the same numbers. Is there a way which I can complete the type conversion without having to do a for loop?
1 Answer
No. You're going to need either a for loop or ten separate statements. The best way would be to write your own conversion function, but I guess you were really wanting to know whether the conversion could be done "in one go", so to speak.
There are two ways of converting types in VHDL. The first is a type conversion:
my_new_type_signal <= my_new_type(my_old_type_signal);
(or variable, obvs). This only works if my_new_type and my_old_type are closely related types. For example, integer and real are closely related, as are std_logic_vector and signed, but your two will not be.
The second way is to write a conversion function. Standard types (from the standard and numeric_std packages) have functions already written. Yours are not standard types, so you'll have to write your own.