Thread: I don't understand this, help? ((boolean))

  1. #1
    C++ and openGL Raeliean's Avatar
    Join Date
    Jul 2005

    I don't understand this, help? ((boolean))

    WTH does this mean?

    A. !( 1 || 0 ) ANSWER: 0
    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

    The way I read it is..
    A. not 1 or 0, false.
    B. not 1 or 1 and 0, false.
    C. not (1 or 0) and 0, true.

    I don't understand it at ALL, what makes them come out true or false or am I just reading it wrong? Can I please get some help?

  2. #2
    Carnivore ('-'v) Hunter2's Avatar
    Join Date
    May 2002
    Read it as a mathematical expression, not as an english phrase. Also remember, 1 means true and 0 means false.

    A. (true or false), take the inverse
    B. [true or (true and false)], take the inverse
    C. [(true or false) and false], take the inverse.

    Where 'take the inverse' means, true->false and false->true.

    You just need to take it in order of operation, where each expression (left <operator> right) evaluates to either true or false. For example:

    (true or false) -> true (an 'or' operation is true if either 'left' or 'right' is true)
    (true and false) -> false (an 'and' operation is false if either 'left' or 'right' is false)
    (true or false) or (true and false) -> (true) or (false) -> true
    Just Google It. √

    (\ /)
    ( . .)
    c(")(") This is bunny. Copy and paste bunny into your signature to help him gain world domination.

  3. #3
    Registered User
    Join Date
    Jun 2004
    In C 0 represents boolean value false. Any other non-zero value is boolean true. Knowing this, and assuming you know what a logic OR and AND is.. good luck.

  4. #4
    Super Moderator
    Join Date
    Sep 2001
    They way you put it, it sounds like you're not familiar with boolean logic and the different functions, so I'll explain those.

    Replace ALL the ones and zeros with true and false, respectively. In logical statements, think of ! as "the opposite of". So let's solve each statement without the !, and then just take the opposite of it.

    The OR function will output true if either operand is true. There's also some variations of OR which don't concern you now.

    So in the first stamment we have the OR function with true and false as operands. At least one of the operands is true, so OR outputs true. Take the opposite of this: false.

    The AND function will output true if an only if both operands are true. In this case at least, AND is evaluated before OR, so lets evaluate it first. AND is given true and true as operands. Obviously, it should output true. So now we have that result, true, and a false as the two operands for the OR function. Again, at least one operand is true, so it outputs true. Don't forget to take the opposite of this, and we get false.

    Then parentheses are interpreted first in every situation I'm aware of in mathematics and programming. Inside the parentheses, we have a true and a flase going to an OR function. Again, this situation will output true. So now we have that result, true, and a false in an AND function. Only one operand is true, so it will output false. Take the opposite, and we have true.

    I hope this makes it clearer for you. Even if you don't see the purpose to this kind of logic yet, just learn the behavior of each function, and eventually you'll get to use it in a practical application - I use it all the time now, actually.

  5. #5
    C++ and openGL Raeliean's Avatar
    Join Date
    Jul 2005
    Thank you all for the help, I think I got it now.

  6. #6
    Deprecated Dae's Avatar
    Join Date
    Oct 2004
    A. !( 1 || 0 ) ANSWER: 0
    B. !( 1 || 1 && 0 ) ANSWER: 0 (AND is evaluated before OR)
    C. !( ( 1 || 0 ) && 0 ) ANSWER: 1 (Parenthesis are useful)

    True = 1;
    False = 0;

    A. opposite (!) of what (1 OR (||) 0) resolves to
    - If its in brackets (parenthesis), do that part first, (1 or 0), well.. it returns true (1) if either are 1, so its returned true (correct) which is 1. So now you have !1, the opposite of 1 is: 0. So the answer is 0.

    B. opposite of (also called NOT) (1 OR 1 AND 0)
    - The symbol that is processed first, || or &&, will effect the outcome, the list of symbols says && is processed first, then || (on that site you read this from). As B says "AND is evaluated before OR".
    - So 1 && 0 returns false (its only true if they are both true), which leaves you with (1 || 0), which returns true: 1, which leaves you with !1, the opposite of 1 is 0. So the answer is 0.

    C. NOT ((1 OR 0) AND 0)
    - The brackets first: (1 OR 0) which returns true: 1, and then leaving you with 1 && 0, which returns false: 0, which leaves you with !0, and that resolves to 1. So the answer is 1.

    I find it impossible to explain this better than the tutorial does. But thats just how I'd break it down if it helps.
    Warning: Have doubt in anything I post.

    GCC 4.5, Boost 1.40, Code::Blocks 8.02, Ubuntu 9.10 010001000110000101100101

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Novice needs help
    By ghaasemi in forum C++ Programming
    Replies: 9
    Last Post: 05-30-2009, 08:20 AM
  2. Casting boolean as string
    By doofusboy in forum C Programming
    Replies: 11
    Last Post: 11-10-2005, 11:24 AM
  3. Replies: 4
    Last Post: 04-02-2004, 06:30 PM
  4. Working with boolean...
    By CompiledMonkey in forum C Programming
    Replies: 4
    Last Post: 11-03-2003, 09:39 AM
  5. Use struct to create a boolean type
    By skyglin in forum C Programming
    Replies: 6
    Last Post: 06-18-2003, 08:21 PM