home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / PROGRAMS / UTILS / FLOPPIES / FDFORMAT.ZIP / SOURCE.ZIP / BASECONV.PAS next >
Encoding:
Pascal/Delphi Source File  |  1989-09-01  |  850 b   |  44 lines

  1. {$A+,B-,D+,E-,F-,I+,L+,N-,O-,R-,S-,V-}
  2. {$M 16384,0,655360}
  3.  
  4. unit baseconv;
  5.  
  6. interface
  7.  
  8. function hexf(x:Longint;a:byte):string;
  9. function dezh(x:string):Longint;
  10.  
  11. const hex:string[16]='0123456789ABCDEF';
  12. Var baseerror: Integer;
  13.  
  14. implementation
  15.  
  16. function hexf(x:Longint;a:byte):string;
  17. begin
  18.   hexf:=hex[succ(x div 16)]+hex[succ(x mod 16)];
  19.   baseerror:=0;
  20.   if x>255 then Baseerror:=1;
  21.   if x<0 then BaseError:=2;
  22. end;
  23.  
  24. function dezh(x:string):Longint;
  25. Var h: Longint;
  26.     i: Longint;
  27. begin
  28.   h:=0;
  29.   BaseError:=0;
  30.   if length(x)>2 then Baseerror:=3;
  31.   if length(x)>1 then begin
  32.     h:=pos(Upcase(x[1]),hex);
  33.     if h=0 then Baseerror:=4;
  34.     h:=pred(h)*16;
  35.   end;
  36.   if length(x)<>0 then begin
  37.     i:=pos(Upcase(x[length(x)]),hex);
  38.     if i=0 then BaseError:=4;
  39.     h:=pred(h)+i;
  40.   end;
  41.   dezh:=h;
  42. end;
  43.  
  44. end.