how to make this algo works in 2.58 ?

i found this little algo but not certain how to make this work in 2.58

the original line for the while was:
while n < i: n = n * 2


 
Find 2^n that is equal to or greater than.
 
"""
 
def nextpow2(i):
 
 n = 2
 
 <b>while n &lt i:</b>
  n = n * 2
 
 return n
 

i get an error on the while line
so can someoine point out how to make this work in 2.58

thanks
happy 2.5

“<” is a html code for “<” char. So your expression should be “while n < i:”

strange that this HTML page is not showing the right code!

i got this one too

k, b, a = 0, N>&gt;1, 1
while b &gt;= a:
if b &amp; i: k = k | a
if a &amp; i: k = k | b
b, a = b>&gt;1, a<&lt;1

any idea what it could be ?

thanks

seriously ricky…


[noparse]
&lt;html&gt;k, b, a = 0, N&gt;&gt;1, 1&lt;br&gt;
while b &gt;= a:&lt;br&gt;
if b & i: k = k | a&lt;br&gt;
if a & i: k = k | b&lt;br&gt;
b, a = b&gt;&gt;1, a&lt;&lt;1&lt;/html&gt;
[/noparse]

save that as a .html and open it in a browser, gives


k, b, a = 0, N&gt;&gt;1, 1
while b &gt;= a:
if b & i: k = k | a
if a & i: k = k | b
b, a = b&gt;&gt;1, a&lt;&lt;1

from http://www.physics.rutgers.edu/~masud/computing/WPark_recipes_in_python.html


# 6.2    bitrev()
# 
# Summary
# Return bit-reversed array for FFT
# Usage
# list = bitrev(list)
"""
Return bit-reversed list, whose length is assumed to be 2^n:
eg. 0111 &lt;--&gt; 1110 for N=2^4.
"""
def bitrev(x):
    N, x = len(x), x[:]
    if N != nextpow2(N): raise ValueError, 'N is not power of 2'
    for i in range(N):
    	k, b, a = 0, N&gt;&gt;1, 1
    	while b &gt;= a:
    	    if b & i: k = k | a
	    if a & i: k = k | b
	    b, a = b&gt;&gt;1, a&lt;&lt;1
	if i &lt; k:		# important not to swap back
	    x[i], x[k] = x[k], x[i]
    return x

why is it not showing it the way it should be and i don’t know how to convert it to normal codes?

is there any reason why you don’t see the right words /code on an HTML page ?

i’d like to make these algos work if possible
but difficult to read it when not sbeing hown as proper code!

mind you there are only 2 algo like that all the other seems ok

thanks