Difference between revisions of "And"
From Free Pascal wiki
Jump to navigationJump to search (→Bitwise operation: mention operands need to be ordinal and it is referred to as a "logical and" in the documentation.) |
(→Boolean operation: Clarify operands must be Boolean) |
||
Line 3: | Line 3: | ||
== Boolean operation == | == Boolean operation == | ||
− | '''And''' produces a value of [[True|true]] if and only if both of its operands are true. | + | '''And''' produces a value of [[True|true]] if and only if both of its Boolean operands are true. |
=== Truth table === | === Truth table === | ||
Line 23: | Line 23: | ||
|style="background: #eeeeee" | true | |style="background: #eeeeee" | true | ||
|} | |} | ||
− | |||
== Bitwise operation == | == Bitwise operation == |
Revision as of 05:48, 14 June 2016
│
Deutsch (de) │
English (en) │
español (es) │
suomi (fi) │
français (fr) │
русский (ru) │
Boolean operation
And produces a value of true if and only if both of its Boolean operands are true.
Truth table
A | B | A and B |
---|---|---|
false | false | false |
false | true | false |
true | false | false |
true | true | true |
Bitwise operation
Logical And (aka Bitwise And) requires ordinal operands and sets a bit in the result variable to 1 if and only if both of the corresponding bits in the operands are 1.
Is power of two
function IsPowerOfTwo( const aValue : longint ): boolean;
var
x : longint;
b : boolean;
begin
b := false;
if aValue <> 0 then
begin
x := aValue - 1;
x := x and aValue;
if x = 0 then b := true;
end;
result := b;
end;
If you call IsPowerOfTwo(4) then you get true. If you call IsPowerOfTwo(5) then you get false .