And
Belongs to : KeywordDescription
The And keyword is used in two different ways:
1. To perform a logical or boolean ‘and’ of two logical values. If both are true, then the result is true, otherwise, the result is false.
2. To perform a mathematical ‘and’ of two integers. The result is a bitwise ‘and’ of the two numbers. For example:
10110001 And 01100110 = 00100000
Notes
If the boolean expression is calculated (as opposed to being a Boolean variable), then brackets are required to isolate it.
Example code
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
var num1, num2, num3 : Integer; letter : Char; begin num1 := $25; // Binary value : 0010 0101 num2 := $32; // Binary value : 0011 0010 // And'ed value : 0010 0000 = $20 = 32 dec letter := 'G'; // And used to return a Boolean value if (num1 > 0) And (letter = 'G') then ShowMessage('Both values are true') else ShowMessage('None or only one true value'); // And used to perform a mathematical AND operation num3 := num1 And num2; ShowMessageFmt('$25 And $32 = $%x',[num3]); end; { Both values are true $25 And $32 = $20 } |