Forum Discussion

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

logarithm to the basis 2

Hi,

is there a way to calculate the logarithm to the basis 2 of a generic parameter? I don't need a synthesizeable circuit. I just want the compiler to to calculate an integer and asign it to another generic parameter of a submodule.

Thanks!

Sören

2 Replies

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

    In VHDL:

    function log2 (x : positive) 
    	return natural 
    	is 
    	begin
    		if x = 1 then
    			return 0 ;
    		else
    			return log2(x / 2) + 1;
    		end if;
    	end function log2 ;