>Hi all,
>
>There's an exponent operator (**), but no log-base-2 (from what
>i could see). Such a function (with integer result) would be useful
>would it not?:
>
>constant MAXADDR: natural:=1000;
>.
>.
>.
>signal addrcntr:unsigned(LOG2(MAXADDR) downto 0);
>
>LOG2 should round upwards.
>
>Could a function be written to do it?
You mean like the ones in this thread?
http://groups.google.com/groups?threadm=iWOC4.143%249o.293380%40news.magma.ca
Regards,
Allan.
function Log2( input:integer ) return integer is
variable temp,log:integer;
begin
temp:=input;
log:=0;
while (temp /= 0) loop
temp:=temp/2;
log:=log+1;
end loop;
return log;
end function log2;
Russell Shaw wrote:
> Hi all,
>
> There's an exponent operator (**), but no log-base-2 (from what
> i could see). Such a function (with integer result) would be useful
> would it not?:
>
> constant MAXADDR: natural:=1000;
> .
> .
> .
> signal addrcntr:unsigned(LOG2(MAXADDR) downto 0);
>
> LOG2 should round upwards.
>
> Could a function be written to do it?
--
--Ray Andraka, P.E.
President, the Andraka Consulting Group, Inc.
401/884-7930 Fax 401/884-7950
email r...@andraka.com
http://www.andraka.com
"They that give up essential liberty to obtain a little
temporary safety deserve neither liberty nor safety."
-Benjamin Franklin, 1759
Russell Shaw wrote:
--
>Hi,
>When I try to connect the nntp: news.magma.ca,
>I get the error like this:
>502 Permission Denied - Denied (Typhoon v1.2.3)
>what should I do?
Trying to connect to someone else's (private) news server is not
likely to be successful.
I suggest using Google, or some other public news archive.
The URL I posted
http://groups.google.com/groups?threadm=iWOC4.143%249o.293380%40news.magma.ca
works. (I just tested it.)
Regards,
Allan.
-- purpose: computes ceil(log2(n))
function log2ceil (n : integer) return integer is
variable m, p : integer;
begin
m := 0;
p := 1;
for i in 0 to n loop
if p < n then
m := m + 1;
p := p * 2;
end if;
end loop;
return m;
end log2ceil;
-- purpose: computes floor(log2(n))
function log2floor (n : integer) return integer is
variable m, p : integer;
begin
m := -1;
p := 1;
for i in 0 to n loop
if p <= n then
m := m + 1;
p := p * 2;
end if;
end loop;
return m;
end log2floor;