3

I was trying to follow this tutorial and came across >>. What exactly does this do?

4

>> 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 0b01000000.

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 mySerial->println(). 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 . operator.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.