Programmable Devices
CPLDs, FPGAs, SoC FPGAs, Configuration, and Transceivers
20641 Discussions

Unsigned number math

Altera_Forum
Honored Contributor II
898 Views

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
0 Kudos
2 Replies
Altera_Forum
Honored Contributor II
191 Views

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.
0 Kudos
Altera_Forum
Honored Contributor II
191 Views

Thanks! Works Great.

0 Kudos
Reply