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 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.

3

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Alexander Ross

Alexander Ross

Gaming, Esports & Interactive Media Writer

Alexander Ross has covered the video game industry for a decade, writing deep dives on game design, esports tournaments, VR developments, and gaming culture.

Share this article
Twitter Facebook Pinterest