How to compare compare std_logic and integer

Why OSVVM?ForumsVHDLHow to compare compare std_logic and integer

This topic has 2 voices, contains 1 reply, and was last updated by Avatar of Jim Lewis Jim Lewis 1683 days ago.

Viewing 2 posts - 1 through 2 (of 2 total)
Author Posts
Author Posts
October 19, 2012 at 12:46 #414
Avatar of Steve Chan
Steve Chan

Hi expert

A supposing easy question.

How to easily compare std_logic to integer of 0 and 1 without using “complex” “if then else” kind statement?

I was trying to find use assert to compare the std_logic and the input vector in integer.

Thanks
  

October 19, 2012 at 13:17 #415
Avatar of Jim Lewis
Jim Lewis

Hi Steve,

CoveragePkg contains a to_integer function for both std_logic and boolean.  So your assertion is no more than:

  signal sig_std_logic : std_logic ;
  signal sig_integer : integer ;
  . . .
  if to_integer(sig_std_logic) = sig_integer then

OTOH, if you are trying to compare a std_logic_vector, use the to_integer function from  package, ieee.numeric_std_unsigned.

The following shows a way to randomize a value between 0 and 1 in std_logic:

TestProc : process

  variable RV : RandomPType ;
  variable B_sl : std_logic ;
begin
  (0 => B_sl) := RV.RandSlv(0, 1, 1) ;

Best, 

Jim

Viewing 2 posts - 1 through 2 (of 2 total)

You must be logged in to reply to this topic.