Forum Discussion

Altera_Forum's avatar
Altera_Forum
Icon for Honored Contributor rankHonored Contributor
14 years ago

Unsigned number math

Greetings,

Apparently when using unsigned numbers if you are performing a math operation using a statement like

if shortwait = (others => '0') then

next line of code....

is not allowed but you can overload an operator and compare it to an integer

if shortwait = 0 then

next line of code....

The above works, Can someone explain to me why I can get away with this and why I cannot use (others => '0') ?

Thanks as always

Bill

2 Replies

  • Altera_Forum's avatar
    Altera_Forum
    Icon for Honored Contributor rankHonored Contributor

    Because the tool doesn't know how large an unsigned (others => '0') should be. You could do something like this, if you were inclined.

    
    constant ZERO : unsigned(shortwait'range) := (others => '0');
    if shortwait = ZERO then
    

    The second equals in question is defined in numeric_std as specifically operating on two operands, one an unsigned and the other an integer, and starts off by defining an unsigned variable of the same length as the operand, mapping the integer into it using TO_UNSIGNED, and then performing the equality comparison.