home *** CD-ROM | disk | FTP | other *** search
- {$A+,B-,D+,E-,F-,I+,L+,N-,O-,R-,S-,V-}
- {$M 16384,0,655360}
-
- unit baseconv;
-
- interface
-
- function hexf(x:Longint;a:byte):string;
- function dezh(x:string):Longint;
-
- const hex:string[16]='0123456789ABCDEF';
- Var baseerror: Integer;
-
- implementation
-
- function hexf(x:Longint;a:byte):string;
- begin
- hexf:=hex[succ(x div 16)]+hex[succ(x mod 16)];
- baseerror:=0;
- if x>255 then Baseerror:=1;
- if x<0 then BaseError:=2;
- end;
-
- function dezh(x:string):Longint;
- Var h: Longint;
- i: Longint;
- begin
- h:=0;
- BaseError:=0;
- if length(x)>2 then Baseerror:=3;
- if length(x)>1 then begin
- h:=pos(Upcase(x[1]),hex);
- if h=0 then Baseerror:=4;
- h:=pred(h)*16;
- end;
- if length(x)<>0 then begin
- i:=pos(Upcase(x[length(x)]),hex);
- if i=0 then BaseError:=4;
- h:=pred(h)+i;
- end;
- dezh:=h;
- end;
-
- end.