Detecting of 'U' in a std_logic_vector

T

Thomas Reinemann

Hello,

I have to convert a std_logic_vector in an integer. This is generally no
matter. But I want to threat vectors in a special way which have 'U's or
'X'. How can I detect whether a vector only contains '0's and '1's.

Bye Tom
 
N

Nicolas Matringe

Thomas Reinemann a écrit:
Hello,

I have to convert a std_logic_vector in an integer. This is generally no
matter. But I want to threat vectors in a special way which have 'U's or
'X'. How can I detect whether a vector only contains '0's and '1's.

Hi
Xor all the bits together (parity check), then pass the result through
the to_x01 function, which will return 'X' for 'U' or 'X' input. Result
should be 0 or 1 if your vector contains only 0s and 1s, or X if not.

Something like
if to_x01(xor_reduce(your_vector)) = 'X' then
...

(xor_reduce function code has been posted here a few weeks ago)
 
A

Allan Herriman

Thomas Reinemann a écrit:

Hi
Xor all the bits together (parity check), then pass the result through
the to_x01 function, which will return 'X' for 'U' or 'X' input. Result
should be 0 or 1 if your vector contains only 0s and 1s, or X if not.

Something like
if to_x01(xor_reduce(your_vector)) = 'X' then
...

(xor_reduce function code has been posted here a few weeks ago)

std_logic_1164 contains these functions:

FUNCTION Is_X ( s : std_ulogic_vector ) RETURN BOOLEAN;
FUNCTION Is_X ( s : std_logic_vector ) RETURN BOOLEAN;
FUNCTION Is_X ( s : std_ulogic ) RETURN BOOLEAN;


if is_x(your_vector) then

.... is much cleaner


Regards,
Allan
 
N

Nicolas Matringe

Allan Herriman a écrit:
std_logic_1164 contains these functions:

FUNCTION Is_X ( s : std_ulogic_vector ) RETURN BOOLEAN;
FUNCTION Is_X ( s : std_logic_vector ) RETURN BOOLEAN;
FUNCTION Is_X ( s : std_ulogic ) RETURN BOOLEAN;


if is_x(your_vector) then

... is much cleaner

Didn't know that. It sure is much cleaner.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,019
Latest member
RoxannaSta

Latest Threads

Top