Copia del wikiespejo

Este es un espejo del wiki de pascal.chat. La edición, el historial y el inicio de sesión están allí.

And/es

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

Operación booleana

Boolean And produce un valor de true si y sólo si ambos operandos booleanos son verdaderos.

Tabla de True

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

Operación a bit

Logical And (también conocido como Bitwise And) requiere operandos ordinales y establece un bit en la variable de resultado a 1 si y sólo si ambos bits correspondientes en los operandos son 1.

Es potencia de dos

pascal
function EsPotenciaDeDos ( const unValor : longint ): boolean;
var
  x : longint;
  b : boolean;
begin
  b := false;
  if unValor <> 0 then
    begin
      x := unValor - 1;
      x := x and unValor;
      if x = 0 then b := true;
    end;
  result := b;
end;

Si llamas a EsPotenciaDeDos(4) entonces obtienes True. Si llamas a EsPotenciaDeDos(5) obtienes False.

También ver


From the Free Pascal wiki, page "And/es", 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.

Revisión 1, último cambio por WikiArchive .