home *** CD-ROM | disk | FTP | other *** search
/ ProfitPress Mega CDROM2 …eeware (MSDOS)(1992)(Eng) / ProfitPress-MegaCDROM2.B6I / UTILITY / SYSTEM / GETTIME.ZIP / HEXDUMP.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1990-11-25  |  1.8 KB  |  78 lines

  1. unit hexdump;
  2. interface
  3. function byte_to_hex (b: byte): string;
  4. function int_to_hex (i: integer): string;
  5. function word_to_hex (i: word): string;
  6. function char_to_hex (c: char): string;
  7. function hex(b: byte): string;
  8. function hexw(w: word): string;
  9. function hexc(c: char): string;
  10. function hexl(l: longint): string;
  11. function hexbytes(var v; size: byte): string;
  12. type wordrec = record
  13.                  lo: byte;
  14.                  hi: byte;
  15.                end;
  16.      longrec = record
  17.                  loword: word;
  18.                  hiword: word;
  19.                end;
  20. implementation
  21. const hexdig: array[0..15] of char = '0123456789ABCDEF';
  22. function hex;
  23. var n1,n2: 0..15;
  24. begin
  25.    n1 := b shr 4;
  26.    n2 := b and $0F;
  27.    hex := hexdig[n1] + hexdig[n2];
  28. end;
  29. function hexc;
  30. begin
  31.   hexc := hex(byte(c));
  32. end;
  33.  
  34. function byte_to_hex (b: byte): string;
  35. var n1,n2: 0..15;
  36. begin
  37.    n1 := b shr 4;
  38.    n2 := b and $0F;
  39.    byte_to_hex := hexdig[n1] + hexdig[n2];
  40. end;
  41. function char_to_hex (c: char): string;
  42. begin
  43.   char_to_hex := byte_to_hex (byte(c));
  44. end;
  45. function int_to_hex (i: integer): string;
  46. begin
  47.   int_to_hex := byte_to_hex (hi(i)) + byte_to_hex (lo(i));
  48. end;
  49. function hexw (w: word): string;
  50. begin
  51.    hexw := byte_to_hex (hi(w)) + byte_to_hex (lo(w));
  52. end;
  53. function word_to_hex;
  54. begin
  55.    word_to_hex := hexw(i);
  56. end;
  57. function hexl(l: longint): string;
  58. var lx: longint;
  59.     lbyte: array[1..4] of byte absolute lx;
  60. begin
  61.    lx := l;
  62.    hexl := hex(lbyte[4]) + hex(lbyte[3]) + hex(lbyte[2]) + hex(lbyte[1]);
  63. end;
  64. function hexbytes(var v; size: byte): string;
  65.     type b127= array[1..127] of byte;
  66. var p: ^b127;
  67.     s: string[255];
  68.     i,j: integer;
  69. begin
  70.   p := @v;
  71.   s := '';
  72.   for i:= 1 to size do begin
  73.      s:=s+hex(p^[i]);
  74.   end;
  75.   hexbytes := s;
  76. end;
  77.  
  78. end.