Thread: Bitwise With If Else Statement

  1. #1
    Registered User
    Join Date
    Sep 2015
    Posts
    3

    Bitwise With If Else Statement

    what does this mean, this condition (z & (1 << 0)) ? ?

    Code:
         
    
    if (strstr(msg, "DO") == msg) //DO=0x[5]
    
    {
           z = strtol(&msg[5], NULL, 16);//HEX
            LATGbits.LATG1 =  (z & (1 << 0)) ? 1 : 0; //lED1 , 0 OFF
            LATGbits.LATG0 =  (z & (1 << 1)) ? 0 : 1; //lED2 , 1 OFF
            LATGbits.LATG13 = (z & (1 << 2)) ? 0 : 1; //lED3 , 1 OFF
            LATGbits.LATG14 = (z & (1 << 3)) ? 0 : 1; //lED4 , 1 OFF
            LATGbits.LATG12 = (z & (1 << 4)) ? 0 : 1; //lED5 , 1 OFF
            sendString("OK\r\n"); //REPLY OK
    }

  2. #2
    Registered User
    Join Date
    May 2010
    Posts
    4,632
    Also posted here.

  3. #3
    Programming Wraith GReaper's Avatar
    Join Date
    Apr 2009
    Location
    Greece
    Posts
    2,738
    "<<" is the bit-shift-to-the-left operator. Here's a wikipedia link
    "&" is the bitwise-and operator. Here's almost the same wikipedia link
    "?" is the ternary operator. Here's another link

    EDIT: LOL, the other thread is linking this one.
    Last edited by GReaper; 09-08-2015 at 10:53 PM.
    Devoted my life to programming...

  4. #4
    Registered User
    Join Date
    Sep 2015
    Posts
    3
    LOL, so jimblumberg is a Skydiver? .
    Last edited by naz1234; 09-08-2015 at 11:51 PM.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. 'If' Statement inside the Switch statement being ignored.
    By howardbc14 in forum C Programming
    Replies: 4
    Last Post: 04-11-2015, 11:45 AM
  2. Bitwise -- b&01
    By ilans11il in forum C Programming
    Replies: 4
    Last Post: 04-22-2013, 03:16 PM
  3. Bitwise and in an if statement?
    By JMK in forum C++ Programming
    Replies: 5
    Last Post: 09-25-2010, 03:55 PM
  4. Statement inside a statement.
    By JOZZY& Wakko in forum C Programming
    Replies: 15
    Last Post: 11-05-2009, 03:18 PM
  5. bitwise IF statement
    By DeeAitch in forum C Programming
    Replies: 3
    Last Post: 12-28-2004, 05:38 AM