Is there an existing function within the regular std.logic library to convert a boolean data type to std logic in vhdl?
Asked
Active
Viewed 3,594 times
2
-
I don't think there is, because I don't know for sure how you would expect it to behave. Let's say the conversion function is `convert(b : boolean) return std_logic`. Then what `std_logic` values would you expect to result from `convert(true)` and `convert(false)`? You could argue that active high and active low logic should give opposite results, so you would want different conversion functions for each case. Conversions in the other direction are even more complicated because you have to decide how to convert 9 different `std_logic` values to just two boolean values. – Harry Jun 04 '21 at 08:19
1 Answers
-1
The answer in short: no.
As @Harry pointed out, it isn't possible to map 2 values from boolean to 9 values from std_logic
.
The std_logic
-type is used, among other things, to detect problems in your code whilst simulating and to have a better representation how the hardware will act later on.
So I would recommend you to not write a function which converts true
to '1'
and false
to '0'
, because then you'll lose the advantage of the std_logic
-type.
It is noted, that converting from std_logic
to boolean
is allowed and even implemented since the VHDL 2008 standard.

Bananenkönig
- 547
- 4
- 12