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/bitSet.adoc
+35-1Lines changed: 35 additions & 1 deletion
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -34,18 +34,52 @@ Sets (writes a 1 to) a bit of a numeric variable.
34
34
35
35
[float]
36
36
=== Returns
37
-
Nothing
37
+
`x`: the value of the numeric variable after the bit at position `n` is set.
38
38
39
39
--
40
40
// OVERVIEW SECTION ENDS
41
41
42
42
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)
0 commit comments