Skip to content

Commit 3d0c3a9

Browse files
authored
Added example code/Notes and warnings
Code was tested on Arduino Mega 2560
1 parent 7ddbe22 commit 3d0c3a9

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

Language/Functions/Bits and Bytes/bitRead.adoc

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,31 @@ The value of the bit (0 or 1).
3838

3939
--
4040
// 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.
4162

63+
Both `x` and `n` must be integer type.
64+
65+
--
4266

4367
// SEE ALSO SECTION
4468
[#see_also]

0 commit comments

Comments
 (0)