bitWrite()

Descripción

Escribe un bit en una variable numérica.

Sintaxis

bitWrite(x, n, b)

Parámetros

  • x: la variable numérica en la que se escribe
  • n: número de bit a escribir, comenzando en 0 del bit menos significatico(más a la derecha)
  • b: el valor del bit a escribir (0 o 1)

Retornos

  • Ninguno

Ejemplo

void setup() { Serial.begin(9600); byte x = 0b10000000; // the 0b prefix indicates a binary constant Serial.print("BEFORE: "); Serial.println(x, BIN); // 10000000 bitWrite(x, 0, 1); // write 1 to the least significant bit of x Serial.print("AFTER: "); Serial.println(x, BIN); // 10000001 } void loop() {}

The result in Serial Monitor:

COM6
Send
BEFORE: 10000000 AFTER: 10000001
Autoscroll Show timestamp
Clear output
9600 baud  
Newline  

ARDUINO BUY RECOMMENDATION

Arduino UNO R3
Arduino Starter Kit
Disclosure: Some links in this section are Amazon affiliate links. If you make a purchase through these links, we may earn a commission at no extra cost to you.
Additionally, some links direct to products from our own brand, DIYables.

※ OUR MESSAGES