Best way to calc next ^2 value...

Blitz3D Forums/Blitz3D Programming/Best way to calc next ^2 value...

If you like puzzles try to figure out why this works.
Graphics 300, 460, 0, 2

For n = 1 To 35
	n2 = NextPowerOfTwo( n )
	Print RSet( n, 5 ) + "  " + n2
Next

WaitKey

Function NextPowerOfTwo( n )
	n = n - 1
	n = n Or ( n Shr 1 )
	n = n Or ( n Shr 2 )
	n = n Or ( n Shr 4 )
	n = n Or ( n Shr 8 )
	n = n Or ( n Shr 16 )
	Return n + 1
End Function