Sign in Join
Wiki copytemporary

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

And/es

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.