Society of Robots - Robot Forum

Software => Software => Topic started by: javila on May 30, 2010, 10:44:25 PM

Title: define port functions for 50$ robot
Post by: javila on May 30, 2010, 10:44:25 PM
Hi:
Can somebody "please" explain to me how this code works:
#define PORT_ON( port_letter, number )         port_letter |= (1<<number)
#define PORT_OFF( port_letter, number )         port_letter &= ~(1<<number)
#define PORT_ALL_ON( port_letter, number )      port_letter |= (number)
#define PORT_ALL_OFF( port_letter, number )      port_letter &= ~(number)
#define FLIP_PORT( port_letter, number )      port_letter ^= (1<<number)
#define PORT_IS_ON( port_letter, number )      ( port_letter & (1<<number) )
#define PORT_IS_OFF( port_letter, number )      !( port_letter & (1<<number) )
I understand basic C and I know what it is doing but do not understand how.
basically I need help with the right side commands. the equal, or, and, shifts, how do they work in this context?
any help will be greatly appreciated.
Title: Re: define port functions for 50$ robot
Post by: cyberfish on June 01, 2010, 10:52:56 PM
They all work in this context just like in any other context.

An equal is an assignment, or, and, and shift are bitwise operators.

What's different about them?

Do you know how macros work?