Skip to content

Replace lost example to bitshiftLeft page #218

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Nov 13, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 18 additions & 0 deletions Language/Structure/Bitwise Operators/bitshiftLeft.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,24 @@ If you are certain that none of the ones in a value are being shifted into obliv
1 << 10 1024
...
----

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:

[source,arduino]
----
// Prints out Binary value (1 or 0) of byte
void printOut1(int c) {
for (int bits = 7; bits > -1; bits--) {
// Compare bits 7-0 in byte
if (c & (1 << bits)) {
Serial.print ("1");
}
else {
Serial.print ("0");
}
}
}
----
[%hardbreaks]

--
Expand Down