bitRead()

설명

숫자의 한 비트를 읽습니다.

문법

bitRead(x, n)

매개변수

  • x: 읽을 숫자
  • n: 읽을 비트, LSB(맨 오른쪽 비트)가 0, 왼쪽으로 갈수록 1씩 증가

반환값

  • 비트의 값 (0 또는 1).

예제 코드

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:

COM6
Send
10000101 10100001
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