home *** CD-ROM | disk | FTP | other *** search
- Function Bit_Change ( Number : Integer ;
- Bit_Position : Byte ;
- Change_Mode : Byte ) : Integer ;
-
- (*
- This function will change the BIT_POSITION bit in NUMBER
- in the manner described by CHANGE_MODE. If CHANGE_MODE
- is 0, then the bit will be turned off; if CHANGE_MODE is
- 1, the bit will be turned on, and if CHANGE_MODE is 2,
- then the bit will be toggled (i.e. if it is off, it will
- be turned on, and if it is on, it will be turned off.)
-
- BIT_POSITION must be in the range 0..15, and CHANGE_MODE
- must be 0, 1, or 2. If either parameter is out of range,
- the function will return NUMBER unchanged.
-
- This function was written by Paul D. Guest and released
- to the Public Domain by same without restrictions on use,
- and with no monetary return expected or desired. Please
- direct comments or questions to the author via "The Indy
- Connection" RBBS @ (317) 846-8675 (24 hrs,7 days/week --
- Paul & Greg McLear, sysops).
- (Enjoy! - pdg 2/85)
-
- *)
-
- Var
- Mask : Integer ;
-
- Begin (* Function Bit_Change *)
-
- If ( Bit_Position IN [ 0 .. 15 ] ) AND
- ( Change_Mode IN [ 0 .. 2 ] ) Then
- Begin
-
- (* Turn the Bit_Position bit on in Mask, and leave the rest off *)
- Mask := 1 SHL Bit_Position ;
-
- Case Change_Mode of
-
- 0 : Bit_Change := Number AND ( $FFFF - Mask ) ;
-
- 1 : Bit_Change := Number OR Mask ;
-
- 2 : Bit_Change := Number XOR Mask ;
-
- End (* Case Change_Mode *)
-
- End (* If ( Bit_Position IN ... ) AND ( Change_Mode IN ... ) *)
-
- Else
- (* Parameters are out of range. Return Number unchanged *)
- Bit_Change := Number
-
- End (* Function Bit_Change *) ;
-