home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
JSAGE
/
ZSUS
/
PROGPACK
/
NZ-TOOL4.LBR
/
RAD.PZS
/
RAD.PAS
Wrap
Pascal/Delphi Source File
|
2000-06-30
|
2KB
|
79 lines
Program RAD;
{$I nz-tool.box}
{$I paramstr.pas}
{
Added the non-builtin function (in Turbo Pascal Version 2) ParamStr. Lee
Bradley, Sysop, Z-Node #12, 203 665-1100 5 Sep 90. Compiled with an End
Address of 3500 hex.
}
Function EVAL(RAD:Integer; NUM:str21):Real;
{ Evaluate a String variable of a given radix 2..16 to decimal Real.}
Const T = '0123456789ABCDEF';
Var N : Real;
Begin
n := 0;
If (1<rad) And (rad<17) Then
While Length(num)<>0 Do
Begin
n := n * rad + Pos(num[1],t)-1;
Delete(num,1,1)
End;
eval := n;
End;
Function CNVRT(R:Integer; V:Real):str21;
{ Convert a decimal Real number to a string of radix 2..16 }
Const D = '0123456789ABCDEF';
Var S : str21;
Begin
s := '0';
If (v>0) And (1<r) And (r<17) Then
Begin
s[0] := #0; { Clear the string }
Repeat
v := v / r;
s := Copy(d,Round(Frac(v)*r+1),1) + s;
v := v - Frac(v);
Until v = 0;
End;
cnvrt := s;
End;
Function RAD(S:str21):Integer;
Var r, c : Integer;
Begin
Case s[1] of
'B','b' : r := 2;
'O','o' : r := 8;
'D','d' : r := 10;
'H','h' : r := 16;
Else
Val(s,r,c)
End;
rad := r;
End;
Var r1, r2 : Integer;
value : Real;
Begin
If (ParamStr(1)='') Or (Pos('/',ParamStr(1))<>0) Then Begin
WriteLn(ParamStr(0),' Number conversion program');
WriteLn(' Syntax: ',ParamStr(0),' nnnn [r1] [r2]');
WriteLn(' where r1 is the input radix, r2 the output');
WriteLn(' radix, any of 2..16, H, D, O or B')
End
Else
Begin
r1 := 16;
r2 := 10;
If Length(ParamStr(3))<>0 Then r2 := rad(ParamStr(3));
If Length(ParamStr(2))<>0 Then r1 := rad(ParamStr(2));
value := eval(r1,ParamStr(1));
Write('Base ',r1,':',r2,' ',cnvrt(r2,value))
End
End.