bitRead()
Description
Reads a bit of a number.
Syntax
bitRead(x, n)
Parameter Values
- x: the number from which to read.
- n: which bit to read, starting at 0 for the least-significant (rightmost) bit.
Return Values
- The value of the bit (0 or 1).
Example Code
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
10000101
10100001
Autoscroll
Clear output
9600 baud
Newline
See Also
- Language : bit()
- Language : bitClear()
- Language : bitSet()
- Language : bitWrite()
- Language : highByte()
- Language : lowByte()
※ ARDUINO BUY RECOMMENDATION
Arduino UNO R3 | |
Arduino Starter Kit |
Please note: These are Amazon affiliate links. If you buy the components through these links, We will get a commission at no extra cost to you. We appreciate it.