What is Operator ^+

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jack.Thomson.v3@gmail.com

    What is Operator ^+

    Why does the following program works, and what is ^+ operator ?

    int main()
    {
    int a = 10;
    int b = 20;
    int c;

    c = a ^+ b;

    printf("Value ===%d", c);

    return 0;
    }
  • Jean-Marc Bourguet

    #2
    Re: What is Operator ^+

    Jack.Thomson.v3 @gmail.com writes:
    Why does the following program works, and what is ^+ operator ?
    c = a ^+ b;
    There is no operator ^+ but there is an unary operator + (like there an
    unary operator -) which you are using here.

    Yours,

    --
    Jean-Marc

    Comment

    • John Bode

      #3
      Re: What is Operator ^+

      On Mar 18, 8:00 am, Jack.Thomson... @gmail.com wrote:
      Why does the following program works, and what is ^+ operator ?
      >
      int main()
      {
      int a = 10;
      int b = 20;
      int c;
      >
      c = a ^+ b;
      >
      printf("Value ===%d", c);
      >
      return 0;
      >
      }
      There is no ^+ operator. The statement is being parsed as

      c = a ^ (+b);

      Comment

      • Jack.Thomson.v3@gmail.com

        #4
        Re: What is Operator ^+

        On Mar 18, 6:17 pm, Jean-Marc Bourguet <j...@bourguet. orgwrote:
        Jack.Thomson... @gmail.com writes:
        Why does the following program works, and what is ^+ operator ?
        c = a ^+ b;
        >
        There is no operator ^+ but there is an unary operator + (like there an
        unary operator -) which you are using here.
        >
        Yours,
        >
        --
        Jean-Marc
        But the output is 30, it is acting same as the addition operator.

        Comment

        • Kenny McCormack

          #5
          Re: What is Operator ^+

          In article <0a162311-f410-477b-bbbc-625256201bd5@u6 9g2000hse.googl egroups.com>,
          John Bode <john_bode@my-deja.comwrote:
          >On Mar 18, 8:00 am, Jack.Thomson... @gmail.com wrote:
          >Why does the following program works, and what is ^+ operator ?
          >>
          >int main()
          >{
          > int a = 10;
          > int b = 20;
          > int c;
          >>
          > c = a ^+ b;
          >>
          > printf("Value ===%d", c);
          >>
          > return 0;
          >>
          >}
          >
          >There is no ^+ operator. The statement is being parsed as
          >
          c = a ^ (+b);
          >
          And ^ is XOR, which means "give me all the bits not in common between
          the two operands". Since 10 is 8+2 and 20 is 16+4, this boils down to
          being equivalent to addition.

          Comment

          • Jean-Marc Bourguet

            #6
            Re: What is Operator ^+

            Jack.Thomson.v3 @gmail.com writes:
            On Mar 18, 6:17 pm, Jean-Marc Bourguet <j...@bourguet. orgwrote:
            Jack.Thomson... @gmail.com writes:
            Why does the following program works, and what is ^+ operator ?
            c = a ^+ b;
            There is no operator ^+ but there is an unary operator + (like there an
            unary operator -) which you are using here.
            >
            But the output is 30, it is acting same as the addition operator.
            There is no bit in common between 10 and 20, so there is no carry to
            propagate and indeed exclusive or behave like addition for these operands.
            But that's quite pecular to these values.

            Yours,

            --
            Jean-Marc

            Comment

            • Richard Tobin

              #7
              Re: What is Operator ^+

              In article <1b379141-f318-451f-96cd-b8ebac4b1967@s8 g2000prg.google groups.com>,
              <Jack.Thomson.v 3@gmail.comwrot e:
              Why does the following program works, and what is ^+ operator ?
              c = a ^+ b;
              >There is no operator ^+ but there is an unary operator + (like there an
              >unary operator -) which you are using here.
              >But the output is 30, it is acting same as the addition operator.
              Try some different numbers. Two equal ones for example.

              -- Richard
              --
              :wq

              Comment

              • Eric Sosman

                #8
                Re: What is Operator ^+

                Jack.Thomson.v3 @gmail.com wrote:
                Why does the following program works, and what is ^+ operator ?
                >
                int main()
                {
                int a = 10;
                int b = 20;
                int c;
                >
                c = a ^+ b;
                >
                printf("Value ===%d", c);
                >
                return 0;
                }
                There is no ^+ operator, but there are ^ and unary +
                operators. The statement is equivalent to

                c = a ^ (+b);

                .... which is equivalent to

                c = a ^ b;

                --
                Eric Sosman
                esosman@ieee-dot-org.invalid

                Comment

                • Kenneth Brody

                  #9
                  Re: What is Operator ^+

                  Jack.Thomson.v3 @gmail.com wrote:
                  >
                  Why does the following program works, and what is ^+ operator ?
                  >
                  int main()
                  {
                  int a = 10;
                  int b = 20;
                  int c;
                  >
                  c = a ^+ b;
                  >
                  printf("Value ===%d", c);
                  >
                  return 0;
                  }
                  There is no "^+" operator. It's simply the binary "^" operator
                  followed by the unary "+" operator. It's equivalent to:

                  c = a ^ ( + b );

                  --
                  +-------------------------+--------------------+-----------------------+
                  | Kenneth J. Brody | www.hvcomputer.com | #include |
                  | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
                  +-------------------------+--------------------+-----------------------+
                  Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>

                  Comment

                  • Kenneth Brody

                    #10
                    Re: What is Operator ^+

                    Jack.Thomson.v3 @gmail.com wrote:
                    >
                    On Mar 18, 6:17 pm, Jean-Marc Bourguet <j...@bourguet. orgwrote:
                    Jack.Thomson... @gmail.com writes:
                    Why does the following program works, and what is ^+ operator ?
                    c = a ^+ b;
                    There is no operator ^+ but there is an unary operator + (like there an
                    unary operator -) which you are using here.
                    >
                    But the output is 30, it is acting same as the addition operator.
                    No, the output happens to give the same results as if you had used
                    addition, but that's only coincidental. It just happens to be that
                    both:

                    10 ^ 20
                    and
                    10 + 20

                    result in the value 30.

                    --
                    +-------------------------+--------------------+-----------------------+
                    | Kenneth J. Brody | www.hvcomputer.com | #include |
                    | kenbrody/at\spamcop.net | www.fptech.com | <std_disclaimer .h|
                    +-------------------------+--------------------+-----------------------+
                    Don't e-mail me at: <mailto:ThisIsA SpamTrap@gmail. com>


                    Comment

                    • Morris Dovey

                      #11
                      Re: What is Operator ^+

                      Jack.Thomson.v3 @gmail.com wrote:
                      But the output is 30, it is acting same as the addition operator.
                      This is one of the cases where a half-adder is enough. :-)

                      --
                      Morris Dovey
                      DeSoto Solar
                      DeSoto, Iowa USA

                      Comment

                      • rpgfan3233

                        #12
                        Re: What is Operator ^+

                        On Mar 18, 8:00 am, Jack.Thomson... @gmail.com wrote:
                        Why does the following program works, and what is ^+ operator ?
                        >
                        int main()
                        {
                                int a = 10;
                                int b = 20;
                                int c;
                        >
                                c = a ^+ b;
                        >
                                printf("Value ===%d", c);
                        >
                                return 0;
                        >
                        }
                        >
                        >
                        Just in case you don't understand, the '+' is NOT addition here. It
                        represents the sign of the number, i.e. "positive b", or 1 * b, if it
                        helps you to think of it that way. In other words:
                        c = a ^+ b;
                        c = a ^ (+b);
                        c = a ^ (1 * b);
                        c = a ^ b;

                        If you used "c = a ^- b," it would be similar, except that you would
                        be performing the bitwise XOR operation on the negative value of 'b'.
                        Obviously the sign of the variable doesn't correspond directly to the
                        sign of the value. After all, if b==-4 then it would be the same as
                        the following:
                        c = a ^+ (-4);
                        c = a ^ (-4);

                        If you used ^-, it would be the following:
                        c = a ^- (-4);
                        c = a ^ -(-4);
                        c = a ^ 4;

                        I hope this helps!

                        Comment

                        • Jack.Thomson.v3@gmail.com

                          #13
                          Re: What is Operator ^+

                          On Mar 19, 2:53 am, rpgfan3233 <rpgfan3...@gma il.comwrote:
                          On Mar 18, 8:00 am, Jack.Thomson... @gmail.com wrote:
                          >
                          >
                          >
                          Why does the following program works, and what is ^+ operator ?
                          >
                          int main()
                          {
                          int a = 10;
                          int b = 20;
                          int c;
                          >
                          c = a ^+ b;
                          >
                          printf("Value ===%d", c);
                          >
                          return 0;
                          >
                          }
                          >
                          Just in case you don't understand, the '+' is NOT addition here. It
                          represents the sign of the number, i.e. "positive b", or 1 * b, if it
                          helps you to think of it that way. In other words:
                          c = a ^+ b;
                          c = a ^ (+b);
                          c = a ^ (1 * b);
                          c = a ^ b;
                          >
                          If you used "c = a ^- b," it would be similar, except that you would
                          be performing the bitwise XOR operation on the negative value of 'b'.
                          Obviously the sign of the variable doesn't correspond directly to the
                          sign of the value. After all, if b==-4 then it would be the same as
                          the following:
                          c = a ^+ (-4);
                          c = a ^ (-4);
                          >
                          If you used ^-, it would be the following:
                          c = a ^- (-4);
                          c = a ^ -(-4);
                          c = a ^ 4;
                          >
                          I hope this helps!


                          Thanks... All the answers helped...

                          Comment

                          Working...