home *** CD-ROM | disk | FTP | other *** search
/ Simtel MSDOS - Coast to Coast / simteldosarchivecoasttocoast.iso / pcmag / vol9n21.zip / DGBIT.PAS < prev    next >
Pascal/Delphi Source File  |  1990-09-25  |  5KB  |  133 lines

  1. {
  2.  ▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄▄
  3.  █                                                                         █
  4.  █        TITLE :      DGBIT.TPU                                           █
  5.  █      PURPOSE :      Bit handing routines.                               █
  6.  █       AUTHOR :      David Gerrold, CompuServe ID:  70307,544            █
  7.  █ ______________________________________________________________________  █
  8.  █                                                                         █
  9.  █   Written in Turbo Pascal, Version 5.5,                                 █
  10.  █   with routines from TurboPower, Object Professional.                   █
  11.  █                                                                         █
  12.  █   Turbo Pascal is a product of Borland International.                   █
  13.  █   Object Professional is a product of TurboPower Software.              █
  14.  █ ______________________________________________________________________  █
  15.  █                                                                         █
  16.  █   This is not public domain software.                                   █
  17.  █   This software is copyright 1990, by David Gerrold.                    █
  18.  █   Permission is hereby granted for personal use.                        █
  19.  █                                                                         █
  20.  █        The Brass Cannon Corporation                                     █
  21.  █        9420 Reseda Blvd., #804                                          █
  22.  █        Northridge, CA  91324-2932.                                      █
  23.  █                                                                         █
  24.  ▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀▀
  25.                                                                             }
  26. { Compiler Directives ===================================================== }
  27.  
  28. {$A-}    {Switch word alignment off, necessary for cloning}
  29. {$R-}    {Range checking off}
  30. {$B-}    {Boolean complete evaluation off}
  31. {$S-}    {Stack checking off}
  32. {$I-}    {I/O checking off}
  33. {$N+,E+} {Simulate numeric coprocessor}
  34. {$M 16384,0,327680} {stack and heap}
  35. {$V-}    {Variable range checking off}
  36.  
  37. { Name ==================================================================== }
  38.  
  39. UNIT DgBit;
  40. {
  41.   The purpose of DgBit is to provide useful bit-handling routines.
  42. }
  43.  
  44. { Interface =============================================================== }
  45.  
  46. INTERFACE
  47.  
  48. { Functions and Procedures ================================================ }
  49.  
  50. FUNCTION SetBitOff (B : word;  Bit: word) : word;
  51.  
  52. FUNCTION SetBitOn (B : word;  Bit: word) : word;
  53.  
  54. FUNCTION ToggleBit (B : word;  Bit : word) : word;
  55. { Flipflops target bit, leaving other bits unchanged. }
  56.  
  57. FUNCTION ToggleBitMask (B : word;  BitMask : word) : word;
  58. { Flipflops target bit value, leaving other bits unchanged. }
  59.  
  60. FUNCTION AndBit (Source, Target : longint) : boolean;
  61. { Returns true if Source contains Target. }
  62.  
  63. { ========================================================================= }
  64. { Implementation ========================================================== }
  65.  
  66. IMPLEMENTATION
  67.  
  68. { ========================================================================= }
  69. { SetBitOff =============================================================== }
  70.  
  71. FUNCTION SetBitOff (B : word;  Bit: word) : word;
  72. BEGIN
  73.   SetBitOff := B and not (1 shl Bit);
  74. END;
  75.  
  76. { SetBitOn ================================================================ }
  77.  
  78. FUNCTION SetBitOn (B : word;  Bit: word) : word;
  79. BEGIN
  80.   SetBitOn := B or (1 shl Bit);
  81. END;
  82.  
  83. { ToggleBit =============================================================== }
  84.  
  85. FUNCTION ToggleBit (B : word;  Bit : word) : word;
  86. { Flipflops target bit, leaving other bits unchanged. }
  87.  
  88. BEGIN
  89.   ToggleBit := ToggleBitMask (B, SetBitOn (0, Bit));
  90. END;
  91.  
  92. { ToggleBitMask =========================================================== }
  93.  
  94. FUNCTION ToggleBitMask (B : word;  BitMask : word) : word;
  95. { Flipflops target bit value, leaving other bits unchanged. }
  96.  
  97. BEGIN
  98.   ToggleBitMask := B xor BitMask;
  99. END;
  100.  
  101. { AndBit ================================================================== }
  102.  
  103. FUNCTION AndBit (Source, Target : longint) : boolean;
  104. { Returns true if Source contains Target. }
  105. BEGIN
  106.   AndBit := Source and Target = Target;
  107. END;
  108.  
  109. { ========================================================================= }
  110. { Initialization ========================================================== }
  111.  
  112. { no initialization needed }
  113. END.
  114.  
  115. { ========================================================================= }
  116. { DgMath History ========================================================== }
  117.  
  118. VERSION HISTORY:
  119.   9005.05
  120.     Totally restructured for consistency with Object Professional.
  121.  
  122. { DgMath Needs ============================================================ }
  123.  
  124. NEED TO ADD:
  125.   Nothing right now.
  126.  
  127. { Bug Reports ============================================================= }
  128.  
  129. BUGS:
  130.   Don't be silly.
  131.  
  132. { ========================================================================= }
  133.