I was trying to follow this tutorial and came across
>>. What exactly does this do?
>> is right shift a value by a certain number of bits.
<< is left shift a value by a certain number of bits.
-> is accessing a member of a class or struct that is referenced by a pointer.
Right Shift and Left Shift
If you have a binary number
0b00010000 and right shift it two bits you get
0b00000100. The C notation for that is
val >> 2. The same for left shift -
val << 2 would result in
Pointers and members
Normally when you access a member of a class or struct you use
., such as
Serial.println(). However it is possible to make a pointer to a class instance, and when you do you need to access the members with
-> instead of
. - such as
This arrow notation serves as syntactic sugar:
mySerial->println() is interpreted as
(*mySerial).println(). The parentheses are necessary because the dereferencing operator
* has a lower order of precedence compared to the dot