Skip to content

Commit 678b21a

Browse files
authored
Merge pull request #884 from HowardWParr/patch-1
Update bitSet.adoc
2 parents 1eafd79 + 2ac5be0 commit 678b21a

File tree

1 file changed

+35
-1
lines changed

1 file changed

+35
-1
lines changed

Language/Functions/Bits and Bytes/bitSet.adoc

Lines changed: 35 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,18 +34,52 @@ Sets (writes a 1 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 set.
3838

3939
--
4040
// OVERVIEW SECTION ENDS
4141

4242

43+
44+
// HOW TO USE SECTION STARTS
45+
[#howtouse]
46+
--
47+
48+
[float]
49+
=== Example Code
50+
Prints the output of `bitSet(x,n)` on two given integers. The binary representation of 4 is 0100, so when `n=1`, the second bit from the right is set to 1. After this we are left with 0110 in binary, so 6 is returned.
51+
52+
[source,arduino]
53+
----
54+
void setup() {
55+
Serial.begin(9600);
56+
while (!Serial) {
57+
; // wait for serial port to connect. Needed for native USB port only
58+
}
59+
60+
int x = 4;
61+
int n = 1;
62+
Serial.print(bitSet(x, n)); // print the output of bitSet(x,n)
63+
}
64+
65+
void loop() {
66+
}
67+
----
68+
[%hardbreaks]
69+
70+
--
71+
// HOW TO USE SECTION ENDS
72+
73+
4374
// SEE ALSO SECTION
4475
[#see_also]
4576
--
4677

4778
[float]
4879
=== See also
4980

81+
[role="language"]
82+
* #LANGUAGE# link:../bitclear[bitClear()]
83+
5084
--
5185
// SEE ALSO SECTION ENDS

0 commit comments

Comments
 (0)