bitRead()

Descripción

Lee un bit de un número.

Sintaxis

bitRead(x, n)

Parámetros

  • x: el número del que se quiere leer
  • n: el bit a leer, empezando por 0 del bit menos significativo (más a la derecha)

Retornos

  • El valor del bit (0 o 1).

Ejemplo

void setup() { Serial.begin(9600); byte x = 0b10000101; // the 0b prefix indicates a binary constant Serial.println(x, BIN); // 10000101 for (int i = 0; i < 8; i++) Serial.print(bitRead(x, i)); // print bits one by one } void loop() {}

The result in Serial Monitor:

Newbiely | Arduino IDE 2.3.8
──
File
Edit
Sketch
Tools
Help
Arduino Uno
Newbiely.ino
···
8 Serial.println("Hello World!");
Output
Serial Monitor
Message (Enter to send message to 'Arduino Uno' on 'COM15')
New Line
9600 baud
10000101 10100001
Ln 11, Col 1
Arduino Uno on COM15
2

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