bitWrite()

설명

숫자 변수의 한 비트를 씁니다.

문법

bitWrite(x, n, b)

매개변수

  • x: 쓸 숫자 변수
  • n: 쓸 비트의 위치, LSB(맨 오른쪽 비트)가 0, 왼쪽으로 갈수록 1씩 증가
  • b: 비트에 쓸 값 (0 또는 1)

반환값

  • 없음

예제 코드

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