Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,31 @@
include c:\cxpl\codes; \intrinsic 'code' declarations
string 0; \use zero-terminated string convention
func Num2Str(N, B); \Convert integer N to a numeric string in base B
int N, B;
char S(32); int I;
[I:= 31;
S(31):= 0; \terminate string
repeat I:= I-1;
N:= N/B;
S(I):= rem(0) + (if rem(0)<=9 then ^0 else ^a-10);
until N=0;
return @S(I); \BEWARE! very temporary string space
];
func Str2Num(S, B); \Convert numeric string S in base B to an integer
char S; int B;
int I, N;
[I:= 0; N:= 0;
while S(I) do
[N:= N*B + S(I) - (if S(I)<=^9 then ^0 else ^a-10); I:= I+1];
return N;
];
[Text(0, Num2Str(0, 10)); CrLf(0);
Text(0, Num2Str(26, 16)); CrLf(0);
Text(0, Num2Str($7FFF_FFFF, 2)); CrLf(0);
IntOut(0, Str2Num("0100", 2)); CrLf(0);
IntOut(0, Str2Num("1a", 16)); CrLf(0);
IntOut(0, Str2Num("deadbeef", 16)); CrLf(0);
]