Data update
This commit is contained in:
parent
5150844a7d
commit
4bb20c9b71
7735 changed files with 38060 additions and 199180 deletions
|
|
@ -1,54 +0,0 @@
|
|||
with Ada.Text_Io; use Ada.Text_Io;
|
||||
with Ada.Strings.Fixed;
|
||||
With Ada.Strings.Unbounded;
|
||||
|
||||
procedure Number_Base_Conversion is
|
||||
Max_Base : constant := 36;
|
||||
subtype Base_Type is Integer range 2..Max_Base;
|
||||
Num_Digits : constant String := "0123456789abcdefghijklmnopqrstuvwxyz";
|
||||
Invalid_Digit : exception;
|
||||
|
||||
function To_Decimal(Value : String; Base : Base_Type) return Integer is
|
||||
use Ada.Strings.Fixed;
|
||||
Result : Integer := 0;
|
||||
Decimal_Value : Integer;
|
||||
Radix_Offset : Natural := 0;
|
||||
begin
|
||||
for I in reverse Value'range loop
|
||||
Decimal_Value := Index(Num_Digits, Value(I..I)) - 1;
|
||||
if Decimal_Value < 0 then
|
||||
raise Invalid_Digit;
|
||||
end if;
|
||||
Result := Result + (Base**Radix_Offset * Decimal_Value);
|
||||
Radix_Offset := Radix_Offset + 1;
|
||||
end loop;
|
||||
return Result;
|
||||
end To_Decimal;
|
||||
|
||||
function To_Base(Value : Natural; Base : Base_Type) return String is
|
||||
use Ada.Strings.Unbounded;
|
||||
Result : Unbounded_String := Null_Unbounded_String;
|
||||
Temp : Natural := Value;
|
||||
Base_Digit : String(1..1);
|
||||
begin
|
||||
if Temp = 0 then
|
||||
return "0";
|
||||
end if;
|
||||
while Temp > 0 loop
|
||||
Base_Digit(1) := Num_Digits((Temp mod Base) + 1);
|
||||
if Result = Null_Unbounded_String then
|
||||
Append(Result, Base_Digit);
|
||||
else
|
||||
Insert(Source => Result,
|
||||
Before => 1,
|
||||
New_Item => Base_Digit);
|
||||
end if;
|
||||
Temp := Temp / Base;
|
||||
end loop;
|
||||
return To_String(Result);
|
||||
end To_Base;
|
||||
|
||||
begin
|
||||
Put_Line("26 converted to base 16 is " & To_Base(26, 16));
|
||||
Put_line("1a (base 16) is decimal" & Integer'image(To_Decimal("1a", 16)));
|
||||
end Number_Base_Conversion;
|
||||
|
|
@ -1,15 +1,15 @@
|
|||
fromBase: function [x,base][
|
||||
if base=2 [ return from.binary x ]
|
||||
if base=8 [ return from.octal x ]
|
||||
if base=16 [ return from.hex x ]
|
||||
if base=2 [ return parse "0b" ++ x ]
|
||||
if base=8 [ return parse "0o" ++ x ]
|
||||
if base=16 [ return parse "0x" ++ x ]
|
||||
|
||||
return to :integer x
|
||||
]
|
||||
|
||||
toBase: function [x,base][
|
||||
if base=2 [ return as.binary x ]
|
||||
if base=8 [ return as.octal x ]
|
||||
if base=16 [ return as.hex x ]
|
||||
if base=2 [ return to :string .format:".b" x ]
|
||||
if base=8 [ return to :string .format:".o" x ]
|
||||
if base=16 [ return to :string .format:".x" x ]
|
||||
|
||||
return to :string x
|
||||
]
|
||||
|
|
|
|||
|
|
@ -1,24 +1,15 @@
|
|||
func$ num2str n base .
|
||||
if n = 0
|
||||
return "0"
|
||||
.
|
||||
if n = 0 : return "0"
|
||||
d = n mod base
|
||||
if d > 9
|
||||
d += 39
|
||||
.
|
||||
if d > 9 : d += 39
|
||||
d$ = strchar (d + 48)
|
||||
if n < base
|
||||
return d$
|
||||
.
|
||||
if n < base : return d$
|
||||
return num2str (n div base) base & d$
|
||||
.
|
||||
func str2num s$ base .
|
||||
r = 0
|
||||
for c$ in strchars s$
|
||||
d = strcode c$ - 48
|
||||
if d > 9
|
||||
d -= 39
|
||||
.
|
||||
if d > 9 : d -= 39
|
||||
r = r * base + d
|
||||
.
|
||||
return r
|
||||
|
|
|
|||
|
|
@ -1,35 +0,0 @@
|
|||
function to_base(integer i, integer base)
|
||||
integer rem
|
||||
sequence s
|
||||
s = ""
|
||||
while i > 0 do
|
||||
rem = remainder(i,base)
|
||||
if rem < 10 then
|
||||
s = prepend(s, '0'+rem)
|
||||
else
|
||||
s = prepend(s, 'a'-10+rem)
|
||||
end if
|
||||
i = floor(i/base)
|
||||
end while
|
||||
|
||||
if length(s) = 0 then
|
||||
s = "0"
|
||||
end if
|
||||
|
||||
return s
|
||||
end function
|
||||
|
||||
function from_base(sequence s, integer base)
|
||||
integer i,d
|
||||
i = 0
|
||||
for n = 1 to length(s) do
|
||||
i *= base
|
||||
if s[n] >= '0' and s[n] <= '9' then
|
||||
d = s[n]-'0'
|
||||
elsif s[n] >= 'a' then
|
||||
d = s[n]-'a'+10
|
||||
end if
|
||||
i += d
|
||||
end for
|
||||
return i
|
||||
end function
|
||||
|
|
@ -1,15 +1,49 @@
|
|||
-- 28 Jul 2025
|
||||
include Settings
|
||||
-- 10 Oct 2025
|
||||
include Setting
|
||||
numeric digits 100
|
||||
arg xx
|
||||
if xx = '' then
|
||||
xx = 255
|
||||
else
|
||||
interpret 'xx='xx
|
||||
|
||||
say 'NON-DECIMAL RADICES CONVERT'
|
||||
say version
|
||||
say
|
||||
do n = 2 to 36
|
||||
say xx 'decimal =' BaseNN(xx,n) 'base' n '=' Base10(BaseNN(xx,n),n) 'decimal'
|
||||
say xx 'decimal =' D2n(xx,n) 'base' n '=' N2d(D2n(xx,n),n) 'decimal'
|
||||
end
|
||||
exit
|
||||
|
||||
include Math
|
||||
N2d:
|
||||
-- Convert base n to base 10
|
||||
procedure
|
||||
arg xx,yy
|
||||
xx=Upper(xx)
|
||||
if yy=2 then
|
||||
return X2D(B2X(xx))+0
|
||||
if yy=16 then
|
||||
return X2D(xx)+0
|
||||
b=XRange('0','9')XRange('A','Z'); l=Length(xx)
|
||||
rr=0
|
||||
do i=1 to l
|
||||
d=Pos(SubStr(xx,i,1),b)-1; rr=rr*yy+d
|
||||
end i
|
||||
return rr
|
||||
|
||||
D2n:
|
||||
-- Convert base 10 to base n
|
||||
procedure
|
||||
arg xx,yy
|
||||
if yy=2 then
|
||||
return X2B(D2X(xx))+0
|
||||
if yy=16 then
|
||||
return D2X(xx)
|
||||
b=XRange('0','9')XRange('A','Z')
|
||||
rr=''
|
||||
do while xx>0
|
||||
r=xx//yy; xx=xx%yy; rr=SubStr(b,r+1,1)rr
|
||||
end
|
||||
return rr
|
||||
|
||||
include Abend
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue