Thread: crazy if statement

  1. #16
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    no i dont want them all on at once like when zone 1 has been used toggle that on soo it cant be used again so i dont get 1 + 1 then when zone 2 is used toggle that on so i dont get 2+2

    just so it stops adding up the values wrong to stop my binary mask

  2. #17
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    . . . there's a reason why me and vart suggested the code that we did.

    Here's an example:

    Code:
    unsigned char x = 0;
    /* x before: 00000000 */
    x |= 0x08;
    /* x now: 00001000 */
    x |= 0x04;
    /* x now: 00001100 */
    x &= ~0x08;
    /* x now: 00000100 */
    It sets *only* that bit, nothing else.

    The binary mask will be fine, that's how you handle binary masks in C.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  3. #18
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    okky it sounds kind of what im after how do i go about doing it ?

  4. #19
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    . . . read the above message(s). Me and vart have explained this no less than 3 times so far.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  5. #20
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by jamespond88 View Post
    okky it sounds kind of what im after how do i go about doing it ?
    Especially for you I have changed my signature
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

  6. #21
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    . . . and I would have too, but it would put it over 500 chars.

    Point is, we're here to help. We're not here to do your work for you.

    Figure out as much as you can yourself, then come back once you have a solid question that actually merits some help. I highly recommend the link in my signature to Eric S. Raymond's "How to ask Smart Questions".
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  7. #22
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    i dont want you to do it but you putting a peice of code in is not making me learn i dont understand the bit of code

  8. #23
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Then what do you not understand about it?? Clarify. Elaborate.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  9. #24
    Registered User
    Join Date
    Mar 2009
    Posts
    11
    you have
    unsigned char x = 0;
    /* x before: 00000000 */
    x |= 0x08;
    /* x now: 00001000 */
    x |= 0x04;
    /* x now: 00001100 */
    x &= ~0x08;
    /* x now: 00000100 */
    is x a int?

    and will this stay toggled and not change any of the values when they are up?

    and

  10. #25
    Officially An Architect brewbuck's Avatar
    Join Date
    Mar 2007
    Location
    Portland, OR
    Posts
    7,396
    Uhm... How come nobody has noticed that you are accidentally using '=' instead of '=='?
    Code:
    //try
    //{
    	if (a) do { f( b); } while(1);
    	else   do { f(!b); } while(1);
    //}

  11. #26
    Resu Deretsiger Nightowl's Avatar
    Join Date
    Nov 2008
    Location
    /dev/null
    Posts
    186
    Correct. x, in this case, is actually an unsigned char, or an 8-bit integer.

    When you toggle a bit to ON, it does not touch the other bits in the mask, no.

    EDIT: I noticed that, brewbuck. Didn't think to mention it, because the whole thing seemed wrong.
    Do as I say, not as I do . . .

    Experimentation is the essence of programming. Just remember to make a backup first.

    "I'm a firm believer that <SomeGod> gave us two ears and one mouth for a reason - we are supposed to listen, twice as much as we talk." - LEAF

    Questions posted by these guidelines are more likely to be answered.

    Debian GNU/Linux user, with the awesome window manager, the git version control system, and the cmake buildsystem generator.

  12. #27
    Hurry Slowly vart's Avatar
    Join Date
    Oct 2006
    Location
    Rishon LeZion, Israel
    Posts
    6,788
    Quote Originally Posted by brewbuck View Post
    Uhm... How come nobody has noticed that you are accidentally using '=' instead of '=='?
    because somebody namely me has noticed. But OP could not elaborate if it was really accidentally or intentionally
    All problems in computer science can be solved by another level of indirection,
    except for the problem of too many layers of indirection.
    – David J. Wheeler

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Usefulness of the "else if" statement
    By gn17 in forum C Programming
    Replies: 7
    Last Post: 08-12-2007, 05:19 AM
  2. If Else statement problem
    By doofusboy in forum C Programming
    Replies: 2
    Last Post: 11-09-2005, 07:18 AM
  3. if/break statement
    By Apropos in forum C++ Programming
    Replies: 7
    Last Post: 02-22-2005, 02:33 PM
  4. string & if statement
    By Curacao in forum C++ Programming
    Replies: 4
    Last Post: 05-02-2003, 09:56 PM
  5. Uh-oh! I am having a major switch problem!
    By goodn in forum C Programming
    Replies: 4
    Last Post: 11-01-2001, 04:49 PM