tasks a-s
This commit is contained in:
parent
47bf37c096
commit
b83f433714
12433 changed files with 156208 additions and 123 deletions
|
|
@ -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);
|
||||
]
|
||||
Loading…
Add table
Add a link
Reference in a new issue