home *** CD-ROM | disk | FTP | other *** search
/ The Unsorted BBS Collection / thegreatunsorted.tar / thegreatunsorted / hacking / phreak_utils_pc / bitmani.pas < prev    next >
Encoding:
Pascal/Delphi Source File  |  1995-04-01  |  2.4 KB  |  88 lines

  1. unit bitmani;
  2.  
  3. interface
  4. uses crt;
  5.  
  6. type Bit_FieldTYP = ARRAY [0..1249] OF byte;
  7.      Bit_FieldPTR = ^Bit_FieldTYP;
  8.  
  9. const bit :array[0..15] of word = (1,2,4,8,16,32,64,128,256,512,1024,
  10.                                    2048,4096,8192,16384,32768);
  11.  
  12. function  GesetztInbyte(BitNr:byte;Testbyte:byte):boolean;
  13. function  GesetztInFeld(BitNr:word;BitFeld:Bit_FieldPTR):boolean;
  14. function  GesetztInword(BitNr:byte;Testword:word):boolean;
  15. procedure SetBitInbyte(BitNr:byte;var Testbyte:byte);
  16. procedure SetBitInword(BitNr:byte;var Testword:word);
  17. procedure SetBitInFeld(BitNr:word;BitFeld:Bit_FieldPtr);
  18. procedure ClrBitInbyte(BitNr:byte;var Testbyte:byte);
  19. procedure ClrBitInword(BitNr:byte;var Testword:word);
  20. procedure ClrBitInFeld(BitNr:word;BitFeld:Bit_FieldPtr);
  21. procedure SwapBit(BitNr:byte; var Testbyte:byte);
  22.  
  23. implementation
  24.  
  25. procedure SetBitInbyte(BitNr:byte; var Testbyte:byte);
  26. begin
  27.   Testbyte:=Testbyte or bit[BitNr];
  28. end;
  29.  
  30. procedure SetBitInword(BitNr:byte; var Testword:word);
  31. begin
  32.   Testword:=Testword or bit[BitNr];
  33. end;
  34.  
  35. procedure SetBitInFeld(BitNr:word; BitFeld:Bit_FieldPtr);
  36. begin
  37.   BitFeld^[BitNr DIV 8]:=BitFeld^[BitNr DIV 8] or bit[BitNr and 7];
  38. end;
  39.  
  40. procedure ClrBitInbyte(BitNr:byte;var Testbyte:byte);
  41. begin
  42.   Testbyte:=Testbyte and NOT bit[BitNr];
  43. end;
  44.  
  45. procedure ClrBitInword(BitNr:byte; var Testword:word);
  46. begin
  47.   Testword:=Testword and NOT bit[BitNr];
  48. end;
  49.  
  50. procedure ClrBitInFeld(BitNr:word; BitFeld:Bit_FieldPtr);
  51. begin
  52.   BitFeld^[BitNr DIV 8] :=
  53.   BitFeld^[BitNr DIV 8] and NOT bit[BitNr and 7];
  54. end;
  55.  
  56. function GesetztInbyte(BitNr,Testbyte:byte):boolean;
  57. begin
  58.   GesetztInbyte:=0 <> (Testbyte and bit[BitNr]);
  59. end;
  60.  
  61. function GesetztInFeld(BitNr:word; BitFeld:Bit_FieldPTR):boolean;
  62. begin
  63.   GesetztInFeld:=0 <> (BitFeld^[BitNr DIV 8] and bit[BitNr and 7]);
  64. end;
  65.  
  66. function GesetztInword(BitNr:byte;Testword:word):boolean;
  67. begin
  68.   GesetztInword:=0<>(Testword and bit[BitNr]);
  69. end;
  70.  
  71. procedure SwapBit(BitNr:byte; var Testbyte:byte);
  72. var Tempbyte :byte;
  73. begin
  74.   Tempbyte:=Testbyte;
  75.   IF GesetztInbyte(BitNr,Tempbyte) then ClrBitInbyte(BitNr,Tempbyte)
  76.     else SetBitInbyte(BitNr,Tempbyte);
  77.   Testbyte:=Tempbyte;
  78. end;
  79.  
  80. begin
  81.   if paramstr(1)='/(C)' then begin
  82.     writeln('BITMANI.PAS  v1.00  Bit Manipulation routines and functions');
  83.     writeln('                    Copyright (C) 1993 by Onkel Dittmeyer/SLAM');
  84.     writeln;
  85.     readln;
  86.   end;
  87. end.
  88.