Author Topic: define port functions for 50$ robot  (Read 961 times)

0 Members and 1 Guest are viewing this topic.

Offline javilaTopic starter

  • Jr. Member
  • **
  • Posts: 31
  • Helpful? 0
define port functions for 50$ robot
« 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.

Offline cyberfish

  • Robot Overlord
  • ****
  • Posts: 163
  • Helpful? 3
Re: define port functions for 50$ robot
« Reply #1 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?

 


Get Your Ad Here