home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / listings / v_01_03 / 1n03009a < prev    next >
Text File  |  1990-07-03  |  2KB  |  66 lines

  1.  
  2. Listing 3
  3.  
  4. {*
  5.  * Returns a 4-digit hex string representing the
  6.  * value of (unsigned integer) word w.
  7.  *}
  8. function hexstr(w : word) : string;
  9.         var
  10.                 s : array [1 .. 4] of char;
  11.                 d, i : integer;
  12.         begin
  13.         for i := 4 downto 1 do
  14.                 begin
  15.                 d := w mod 16;
  16.                 if d < 10 then
  17.                         d := d + ord('0')
  18.                 else
  19.                         d := d - 10 + ord('A');
  20.                 s[i] := chr(d);
  21.                 w := w div 16;
  22.                 end;
  23.         hexstr := s;
  24.         end;
  25.  
  26. {*
  27.  * Returns a string representing pointer p in the form
  28.  * SSSS:OOOO, where SSSS is the 4-digit hex representa-
  29.  * tion of the segment portion of p, and OOOO is the
  30.  * 4-digit hex representation of the offset portion of
  31.  * p.
  32.  *}
  33. function ptrstr(p : pointer) : string;
  34.         type
  35.                 pc = ^char;
  36.         begin
  37.         ptrstr :=
  38.                 hexstr(seg(pc(p)^)) + ':' +
  39.                 hexstr(ofs(pc(p)^));
  40.         end;
  41.  
  42. var
  43.         p1, p2, p3, p4 : ^longint;
  44. begin
  45. new(p1);
  46. p1^ := 1;
  47. writeln('p1 = ', ptrstr(p1), ', p1^ = ', p1^);
  48. new(p2);
  49. p2^ := 2;
  50. writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
  51. new(p3);
  52. p3^ := 3;
  53. writeln('p3 = ', ptrstr(p3), ', p3^ = ', p3^);
  54. dispose(p2);
  55. writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
  56. new(p4);
  57. p4^ := 4;
  58. writeln('p4 = ', ptrstr(p4), ', p4^ = ', p4^);
  59. writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
  60. p2^ := -2;
  61. writeln('p2 = ', ptrstr(p2), ', p2^ = ', p2^);
  62. writeln('p4 = ', ptrstr(p4), ', p4^ = ', p4^);
  63. end.
  64.  
  65.  
  66.