You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: Language/Functions/Bits and Bytes/bitRead.adoc
+24Lines changed: 24 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -38,7 +38,31 @@ The value of the bit (0 or 1).
38
38
39
39
--
40
40
// OVERVIEW SECTION ENDS
41
+
=== Example Code
42
+
// Describe what the example code is all about and add relevant code
43
+
Reads the bit at the specified position and returns the value. In this example the binary representation of 6 is 0110, since `n=1` the value of the second bit from the right (which is 1 in this case) will be read and printed.
44
+
[source,arduino]
45
+
----
46
+
void setup()
47
+
{
48
+
Serial.begin(9600);
49
+
}
50
+
51
+
void loop()
52
+
{
53
+
int x = 6; int n = 1; //setting the value of x and n
54
+
Serial.print(bitRead(x,n)); //reading the bit at position n and printing the value
55
+
}
56
+
----
57
+
[%hardbreaks]
58
+
59
+
[float]
60
+
=== Notes and Warnings
61
+
The indexing of the rightmost bit starts from 0, so `n=1` reads the second bit from the right.
0 commit comments