bitAnd
bitAnd(op: Byte): Byte;
The bitAnd method of the Byte primitive type compares each bit in the receiver with the corresponding bit specified in the op parameter and returns a Byte value representing the receiver bits ANDed with the argument.
The generated return values are listed in the following table.
Bits in Receiver and Operand | Corresponding Bit in Return Value |
---|---|
Both bits are 1 | 1 |
One or both bits are not 1 | 0 |
The following example shows the use of the bitAnd method.
keyDown(keyCode: Integer io; shift: Integer) updating; constants Shift = 1.Byte; Cntrl = 2.Byte; Alt = 4.Byte; vars byt : Byte; begin byt := shift.Byte; if byt.bitAnd(Shift) <> 0 then write "Shift key is down"; endif; if byt.bitAnd(Cntrl) <> 0 then write "Control key is down"; endif; if byt.bitAnd(Alt) <> 0 then write "Alt key is down"; endif; end;