Difference between revisions of "And"
From Free Pascal wiki
Jump to navigationJump to searchm |
m (Use wiki standard heading level: start with level 2. Added link to see also) |
||
Line 1: | Line 1: | ||
{{And}} | {{And}} | ||
− | = 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 operands are true. | ||
− | == Truth table == | + | === Truth table === |
{| class="wikitable" | {| class="wikitable" | ||
Line 25: | Line 25: | ||
− | = Bitwise operation = | + | == Bitwise operation == |
Bitwise and sets a bit to 1 if and only if all of the corresponding bits in its operands are 1. | Bitwise and sets a bit to 1 if and only if all of the corresponding bits in its operands are 1. | ||
− | == Is power of two == | + | === Is power of two === |
<syntaxhighlight> | <syntaxhighlight> | ||
Line 48: | Line 48: | ||
</syntaxhighlight> | </syntaxhighlight> | ||
− | If you call IsPowerOfTwo(4) then get true. If you call IsPowerOfTwo(5) then get false . | + | If you call IsPowerOfTwo(4) then you get true. If you call IsPowerOfTwo(5) then you get false . |
− | == | + | == See also == |
* [[Not]] | * [[Not]] | ||
* [[Shl]] | * [[Shl]] | ||
Line 59: | Line 59: | ||
* [[Shl# Clear a bit|Clear a bit]] | * [[Shl# Clear a bit|Clear a bit]] | ||
+ | * [[Bit manipulation]] | ||
[[Category:Pascal]] | [[Category:Pascal]] |
Revision as of 14:23, 5 May 2014
│
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 operands are true.
Truth table
A | B | A and B |
---|---|---|
false | false | false |
false | true | false |
true | false | false |
true | true | true |
Bitwise operation
Bitwise and sets a bit to 1 if and only if all of the corresponding bits in its 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 .