Skip to content

Commit 341f158

Browse files
authored
Added Example Code/ Notes and warnings
There was no example code given, and the returns section was incorrect. The code was tested on Arduino Mega 2560.
1 parent 7ddbe22 commit 341f158

File tree

1 file changed

+27
-1
lines changed

1 file changed

+27
-1
lines changed

Language/Functions/Bits and Bytes/bitClear.adoc

+27-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ Clears (writes a 0 to) a bit of a numeric variable.
3434

3535
[float]
3636
=== Returns
37-
Nothing
37+
`x`: the value of the numeric variable after the bit at position `n` is cleared.
3838

3939
--
4040
// OVERVIEW SECTION ENDS
@@ -45,6 +45,32 @@ Nothing
4545
--
4646

4747
[float]
48+
=== Example Code
49+
// Describe what the example code is all about and add relevant code
50+
Prints the output of `bitClear(x,n)` on two given integers. The binary representation of 6 is 0110, so when `n=1`, the second bit from the right is set to 0. After this we are left with 0100 in binary, so 4 is returned.
51+
52+
[source,arduino]
53+
----
54+
void setup()
55+
{
56+
Serial.begin(9600);
57+
}
58+
59+
void loop()
60+
{
61+
int x = 6; int n = 1; //setting the value of x and n
62+
Serial.print(bitClear(x,n)); //printing the output of the bitClear(x,n)
63+
}
64+
----
65+
[%hardbreaks]
66+
67+
[float]
68+
=== Notes and Warnings
69+
The indexing of the rightmost bit starts from 0, so `n=1` clears the second bit from the right. If the bit at any given position is already zero, `x` is returned unchanged.
70+
71+
Both `x` and `n` must be integers.
72+
73+
--
4874
=== See also
4975

5076
--

0 commit comments

Comments
 (0)