Diferencia entre revisiones de «not»

De ArduWiki
Saltar a: navegación, buscar
(Vea también)
(Vea también)
Línea 58: Línea 58:
 
== Vea también ==
 
== Vea también ==
 
<categorytree mode=all>Operador logico</categorytree>
 
<categorytree mode=all>Operador logico</categorytree>
* [[and]] <nowiki>(&&)</nowiki>
 
* [[or]] <nowiki>(||)</nowiki>
 
* [[not bit a bit]] <nowiki>(~)</nowiki>
 
* [[and bit a bit]] <nowiki>(&)</nowiki>
 
* [[or bit a bit]] <nowiki>(|)</nowiki>
 
* [[xor bit a bit]] <nowiki>(^)</nowiki>
 
* [[bitshift right]] <nowiki>(>>)</nowiki>
 
* [[bitshift left]] <nowiki>(<<)</nowiki>
 
  
 
== Referencias ==
 
== Referencias ==

Revisión del 19:27 14 jun 2019

Descripción

Niega una expresión (invierte su valor de verdad) se representa con carácter de admiración (!).

a !a
0 1
1 0

Nota: Recuerde que false, 0 y LOW son sinonimos, si como true, cualquier numero distinto a o y HIGH también lo son.


Sintaxis

!variable;
!expresion;

Parámetros

variable
variable del tipo boleana. Ejemplo q=false;
expresion
expresion cuya evaluacion debe ser verdero o falso. Ejemplo x>5;

Retorno

Retorna la variable negada.

Advertencias

  • No confundir el operador boleano not (!), con el operador not bit a bit (~).

Ejemplo 1

bool a = false;
bool a = 0;
bool a = LOW;
!a           //verdadedo en todos los casos

Ejemplo 2

byte a=5;
a>2;    //Verdadero
!a>2;   //Falso

Ejemplo 3

Un parpadeo simple del LED a bordo.

void setup(){
   pinMode(LED_BUILTIN, OUTPUT);
}
void loop(){
   digitalWrite(LED_BUILTIN, !digitalRead(LED_BUILTIN));
   delay(500);
}

Vea también

  and
  not
  or
  xor


Referencias