Skip to content

Commit ad8de3f

Browse files
author
SimonePDA
authored
Merge pull request #218 from per1234/bitShiftLeft-example
Replace lost example to bitshiftLeft page
2 parents 7e631f9 + ab4dd34 commit ad8de3f

File tree

1 file changed

+18
-0
lines changed

1 file changed

+18
-0
lines changed

Language/Structure/Bitwise Operators/bitshiftLeft.adoc

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -81,6 +81,24 @@ If you are certain that none of the ones in a value are being shifted into obliv
8181
1 << 10 1024
8282
...
8383
----
84+
85+
The following example can be used to print out the value of a received byte to the serial monitor, using the left shift operator to move along the byte from bottom(LSB) to top (MSB), and print out its Binary value:
86+
87+
[source,arduino]
88+
----
89+
// Prints out Binary value (1 or 0) of byte
90+
void printOut1(int c) {
91+
for (int bits = 7; bits > -1; bits--) {
92+
// Compare bits 7-0 in byte
93+
if (c & (1 << bits)) {
94+
Serial.print ("1");
95+
}
96+
else {
97+
Serial.print ("0");
98+
}
99+
}
100+
}
101+
----
84102
[%hardbreaks]
85103

86104
--

0 commit comments

Comments
 (0)