Re: Question About Z-Level Number Thingie
Gabriel Boehme wrote:
>Further suggestions/modifications/improvements are encouraged!
Here is a slight improvement of my original routine (recursion retained)
and a slight improvement of your second routine (doesn't need the reverse=
()
function). It passes the sanity test, but still doesn't like negative
numbers.
- Colin
constant CHAR =3D "0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZ"
function convert_base(integer num, integer base)
sequence out_str
out_str =3D ""
if num >=3D base then
out_str =3D convert_base(floor(num/base), base)
end if
return out_str & CHAR[remainder(num, base)+1]
end function
function read_base(sequence num, integer base)
integer out_num, len
len =3D length(num)
out_num =3D 0
for i =3D 1 to len do
out_num +=3D (find(num[i], CHAR)-1)*power(base, len-i)
end for
return out_num
end function
|
Not Categorized, Please Help
|
|