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: content/learn/03.programming/09.bit-mask/bit-mask.md
+8-8Lines changed: 8 additions & 8 deletions
Original file line number
Diff line number
Diff line change
@@ -13,8 +13,8 @@ The AND (&) operator will result in a 1 at each bit position where both input va
13
13
For example:
14
14
15
15
```arduino
16
-
x: 10001101
17
-
16
+
x: 10001101
17
+
18
18
y: 01010111
19
19
20
20
x & y: 00000101
@@ -24,7 +24,7 @@ The OR (|) operator (also known as Inclusive Or) will result in a 1 at each bit
24
24
For example:
25
25
26
26
```arduino
27
-
x: 10001101
27
+
x: 10001101
28
28
29
29
y: 01010111
30
30
@@ -35,7 +35,7 @@ The Left Shift (<<) operator will shift a value to the left the specified number
35
35
For example:
36
36
37
37
```arduino
38
-
y = 1010
38
+
y = 1010
39
39
40
40
x = y << 1
41
41
@@ -48,7 +48,7 @@ The Right Shift (>>) operator works identically to left shift except that it shi
48
48
For example:
49
49
50
50
```arduino
51
-
y = 1010
51
+
y = 1010
52
52
53
53
x = y >> 1
54
54
@@ -97,7 +97,7 @@ void loop()
97
97
Here we use a FOR loop to iterate through a bit mask value, shifting the value one position left each time through the loop. In this example we use the <<= operator which is exactly like the << operator except that it compacts the statement
98
98
99
99
```arduino
100
-
00000001
100
+
00000001
101
101
& 10101010
102
102
103
103
________
@@ -109,12 +109,12 @@ And our output pin gets set to 0.
109
109
Second time through the loop the mask = 00000010, so our operation looks like:
110
110
111
111
```arduino
112
-
00000010
112
+
00000010
113
113
& 10101010
114
114
115
115
________
116
116
117
117
00000010
118
118
```
119
119
120
-
And our output pin gets set to 1. The loop will continue to iterate through each bit in the mask until the 1 gets shifted left off the end of the 8 bits and our mask =0. Then all 8 bits have been sent and our loop exits.
120
+
And our output pin gets set to 1. The loop will continue to iterate through each bit in the mask until the 1 gets shifted left off the end of the 8 bits and our mask =0. Then all 8 bits have been sent and our loop exits.
0 commit comments