Sign in Join
Wiki copytemporary

Revision 1 of 1, by Trev on 1-26-2020. The page as it is now.

And/fr

Opération booléenne

And produit une valeur true si et seulement si ses deux opérandes sont True ensemble.

Table de vérité

A B A and B
  false     false     false
  false   true   false
  true   false   false
  true   true   true

Opération bit à bit

And bit à bit met à 1 un bit si les bits correspondant des opérandes sont égaux à 1.

Est une puissance de 2

pascal
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;

Si vous appelez IsPowerOfTwo(4) alors vous obtenez True. SI vous appelez IsPowerOfTwo(5) alors vous obtenez False .

Voir aussi


From the Free Pascal wiki, page "And/fr", as it stood on 2020-01-26 after a change by Trev, out of the wiki's dump of 2024-05-26. Copyright stays with the author who wrote it, according to the old wiki's Licensing page. If you have concerns about this material, message the admin.