home *** CD-ROM | disk | FTP | other *** search
/ Programmer 7500 / MAX_PROGRAMMERS.iso / INFO / TURBOPAS / TPBASIC.ZIP / BITCHG.PAS < prev    next >
Encoding:
Pascal/Delphi Source File  |  1985-02-26  |  1.9 KB  |  56 lines

  1. Function Bit_Change ( Number       : Integer ;
  2.                       Bit_Position : Byte ;
  3.                       Change_Mode  : Byte      ) : Integer ;
  4.  
  5.     (*
  6.         This function will change the BIT_POSITION bit in NUMBER
  7.         in the manner described by CHANGE_MODE.  If CHANGE_MODE
  8.         is 0, then the bit will be turned off; if CHANGE_MODE is
  9.         1, the bit will be turned on, and if CHANGE_MODE is 2,
  10.         then the bit will be toggled (i.e. if it is off, it will
  11.         be turned on, and if it is on, it will be turned off.)
  12.  
  13.         BIT_POSITION must be in the range 0..15, and CHANGE_MODE
  14.         must be 0, 1, or 2.  If either parameter is out of range,
  15.         the function will return NUMBER unchanged.
  16.  
  17.         This function was written by Paul D. Guest and released
  18.         to the Public Domain by same without restrictions on use,
  19.         and with no monetary return expected or desired.  Please
  20.         direct comments or questions to the author via "The Indy
  21.         Connection" RBBS @ (317) 846-8675 (24 hrs,7 days/week --
  22.         Paul & Greg McLear, sysops).
  23.         (Enjoy! - pdg 2/85)
  24.  
  25.     *)
  26.  
  27. Var
  28.     Mask : Integer ;
  29.  
  30. Begin (* Function Bit_Change *)
  31.  
  32.     If ( Bit_Position IN [ 0 .. 15 ] ) AND
  33.        ( Change_Mode  IN [ 0 ..  2 ] )     Then
  34.         Begin
  35.  
  36.             (* Turn the Bit_Position bit on in Mask, and leave the rest off *)
  37.         Mask := 1 SHL Bit_Position ;
  38.  
  39.         Case Change_Mode of
  40.  
  41.             0 : Bit_Change := Number AND ( $FFFF - Mask ) ;
  42.  
  43.             1 : Bit_Change := Number OR Mask ;
  44.  
  45.             2 : Bit_Change := Number XOR Mask ;
  46.  
  47.             End (* Case Change_Mode *)
  48.  
  49.         End (* If ( Bit_Position IN ... ) AND ( Change_Mode IN ... ) *)
  50.  
  51.     Else
  52.             (* Parameters are out of range.  Return Number unchanged *)
  53.         Bit_Change := Number
  54.  
  55. End (* Function Bit_Change *) ;
  56.