Understanding some arduino code

Discussion in 'General Off-Topic Chat' started by camochase, Nov 13, 2013.

  1. camochase
    OP

    camochase GBAtemp Regular

    Member
    164
    6
    Oct 26, 2010
    United States
    So im looking at some code that takes the data of a snes controller and displays what is being pressed in the debug. I have never used arduino so im just trying to understand it it says
    Code:
    if (ControllerData & SNES_B) {
    Serial.print(" B");
    }
    what exactly does the & symbol do in the condition?
     
  2. ResleyZ

    ResleyZ Swiggity swaggity swooty, I love my own booty

    Member
    528
    119
    Oct 11, 2013
    Netherlands
    Silicon Valley
    It seems that Arduino uses either C+ or C++, in which case the & symbol shows where the address will be taken from. In this case it takes the ControllerData from SNES_B. It might be useful to read a little introduction to C++, since it is always helpful to understand the basics. Not sure though, so I may be wrong :P
     
  3. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,537
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    PityOnU likes this.
  4. camochase
    OP

    camochase GBAtemp Regular

    Member
    164
    6
    Oct 26, 2010
    United States
    I do understand C but the problem was i couldnt see how it was a condition that would work with an if statement but foxi4's comment on how it helps distinguish between buttons helped alot and sorry for not posting what controller data and things are
     
  5. Foxi4

    Foxi4 On the hunt...

    pip Reporter
    23,537
    21,496
    Sep 13, 2009
    Poland
    Gaming Grotto
    If you don't have a comparison operator in an if statement, the the compiler assumes that you mean if(statement is true?). :)
     
  6. PityOnU

    PityOnU GBAtemp Advanced Fan

    Member
    907
    327
    Jul 5, 2012
    United States
    Arduino code is closer to Java, so... not even close.

    Snaps for Foxi.
     
  7. megazig

    megazig SU

    Member
    467
    93
    Oct 25, 2008
    United States
    raulpica likes this.