Boolean problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • anorisml
    New Member
    • Oct 2007
    • 4

    #1

    Boolean problem

    Hi guys! I would like to know if anyone can help me with this:
    i must make a difference between two variables ('t' and 'o') which are both boolean: t-0. i don't know how i can do it, and i would appreciate if anyone could help me. the language is C++.
    thanks
    anoris
  • khosrow
    New Member
    • Aug 2007
    • 9

    #2
    what do you mean by "making a diffrence" ?

    Comment

    • anorisml
      New Member
      • Oct 2007
      • 4

      #3
      Originally posted by khosrow
      what do you mean by "making a diffrence" ?
      sorry the "bad language"
      a quantity minus outher.somethin g like the mathematical subtraction:
      5-3=2

      Comment

      • Ganon11
        Recognized Expert Specialist
        • Oct 2006
        • 3651

        #4
        If your variables are both booleans, then you have a few possibilities:

        T and O are both TRUE. C++ represents TRUE as 1, so you will have 1-1 = 0, which is interpreted as FALSE.

        T and O are both FALSE - this is 0-0 = 0 which is FALSE.

        T is TRUE and O is FALSE, then you have 1-0 = 1 which is TRUE. Alternatively, if T is FALSE and O is TRUE, then you have 0-1 = -1 which I think is also TRUE.

        Comment

        • Laharl
          Recognized Expert Contributor
          • Sep 2007
          • 849

          #5
          Originally posted by Ganon11
          Alternatively, if T is FALSE and O is TRUE, then you have 0-1 = -1 which I think is also TRUE.
          -1 should be TRUE, since 0-1 is equivalent to 1-0 in truth value, as the - basically represents an OR relationship.
          Last edited by Laharl; Oct 7 '07, 01:08 AM. Reason: typos...

          Comment

          • anorisml
            New Member
            • Oct 2007
            • 4

            #6
            Yes, I know all of that, but what I really wanted to know was how to do it in C++. I will need that result to do other things. Meanwhile I spoke to a colleague of mine which said that I could do the code like this:
            Code:
            bool g, t, o;
            (...)
            g=t^o;
            and the result, g, would always give me the expected value. I checked, and, as a matter of fact, the result that appears is always what it should give. What I would now like to know is if this is a correct way of doing it, or if any problem will come out of this. If anyone knows anything about this, than I would be really appreciate.
            Anoris

            Comment

            • JosAH
              Recognized Expert MVP
              • Mar 2007
              • 11453

              #7
              Originally posted by anorisml
              Yes, I know all of that, but what I really wanted to know was how to do it in C++. I will need that result to do other things. Meanwhile I spoke to a colleague of mine which said that I could do the code like this:
              Code:
              bool g, t, o;
              (...)
              g=t^o;
              and the result, g, would always give me the expected value. I checked, and, as a matter of fact, the result that appears is always what it should give. What I would now like to know is if this is a correct way of doing it, or if any problem will come out of this. If anyone knows anything about this, than I would be really appreciate.
              Anoris
              There is no arithmetic '-' (minus) defined for a Boolean algebra; the 'difference'
              of two boolean values could be defined as 'a^b', what you did, and it is equivalent
              to 'a != b' which maybe looks less cryptic.

              kind regards,

              Jos

              Comment

              Working...