Copie du wikimiroir

Ceci est un miroir du wiki de pascal.chat. La modification, l’historique et la connexion se trouvent là-bas.

And/fr

Deutsch · English · Español · Français · Suomi · Русский

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.

Version 1, dernière modification par WikiArchive .