Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
|
|
@ -0,0 +1,31 @@
|
|||
#converts a number to a given based represented by a string
|
||||
to_base := proc(num, based)
|
||||
local i;
|
||||
local chart := "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
local conversion := ListTools:-Reverse((convert(num,base,based)));
|
||||
local str := StringTools:-StringBuffer();
|
||||
for i in conversion do
|
||||
str:-append(chart[i+1]);
|
||||
end do;
|
||||
return str;
|
||||
end proc:
|
||||
|
||||
#find the location of char in chart
|
||||
find_digit := proc(char)
|
||||
if (StringTools:-HasAlpha(char)) then
|
||||
return (StringTools:-Ord(char) - 87);
|
||||
else
|
||||
return (StringTools:-Ord(char) - 48);
|
||||
end if;
|
||||
end proc:
|
||||
|
||||
#converts a string with given base to a number
|
||||
from_base := proc(str, base)
|
||||
local char;
|
||||
local result := 0;
|
||||
for char in str do
|
||||
result *= base;
|
||||
result += find_digit(char);
|
||||
end do;
|
||||
return result;
|
||||
end proc:
|
||||
Loading…
Add table
Add a link
Reference in a new issue