bitWrite()

Description

Ecrit (càd fixe la valeur) d'un bit d'une variable numérique.

Syntaxe

bitWrite(x, n, b)

Paramètres

  • x: la variable numérique le bit doit être écrit.
  • n: le rang du bit à écrire, en partant du 0 pour le bit de poids faible (le plus à droite)
  • b: la valeur à écrire dans le bit (0 or 1).

Valeurs Renvoyées

  • Aucune

Exemple

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:

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
BEFORE: 10000000 AFTER: 10000001
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