Connecting Tech Pros Worldwide Forums | Help | Site Map

What is Operator ^+

Jack.Thomson.v3@gmail.com
Guest
 
Posts: n/a
#1: Mar 18 '08
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
Guest
 
Posts: n/a
#2: Mar 18 '08

re: What is Operator ^+


Jack.Thomson.v3@gmail.com writes:
Quote:
Why does the following program works, and what is ^+ operator ?
Quote:
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
John Bode
Guest
 
Posts: n/a
#3: Mar 18 '08

re: What is Operator ^+


On Mar 18, 8:00 am, Jack.Thomson...@gmail.com wrote:
Quote:
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);

Jack.Thomson.v3@gmail.com
Guest
 
Posts: n/a
#4: Mar 18 '08

re: What is Operator ^+


On Mar 18, 6:17 pm, Jean-Marc Bourguet <j...@bourguet.orgwrote:
Quote:
Jack.Thomson...@gmail.com writes:
Quote:
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.
Kenny McCormack
Guest
 
Posts: n/a
#5: Mar 18 '08

re: What is Operator ^+


In article <0a162311-f410-477b-bbbc-625256201bd5@u69g2000hse.googlegroups.com>,
John Bode <john_bode@my-deja.comwrote:
Quote:
>On Mar 18, 8:00 am, Jack.Thomson...@gmail.com wrote:
Quote:
>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.

Jean-Marc Bourguet
Guest
 
Posts: n/a
#6: Mar 18 '08

re: What is Operator ^+


Jack.Thomson.v3@gmail.com writes:
Quote:
On Mar 18, 6:17 pm, Jean-Marc Bourguet <j...@bourguet.orgwrote:
Quote:
Jack.Thomson...@gmail.com writes:
Quote:
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
Richard Tobin
Guest
 
Posts: n/a
#7: Mar 18 '08

re: What is Operator ^+


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

-- Richard
--
:wq
Eric Sosman
Guest
 
Posts: n/a
#8: Mar 18 '08

re: What is Operator ^+


Jack.Thomson.v3@gmail.com wrote:
Quote:
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
Kenneth Brody
Guest
 
Posts: n/a
#9: Mar 18 '08

re: What is Operator ^+


Jack.Thomson.v3@gmail.com wrote:
Quote:
>
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:ThisIsASpamTrap@gmail.com>

Kenneth Brody
Guest
 
Posts: n/a
#10: Mar 18 '08

re: What is Operator ^+


Jack.Thomson.v3@gmail.com wrote:
Quote:
>
On Mar 18, 6:17 pm, Jean-Marc Bourguet <j...@bourguet.orgwrote:
Quote:
Jack.Thomson...@gmail.com writes:
Quote:
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:ThisIsASpamTrap@gmail.com>


Morris Dovey
Guest
 
Posts: n/a
#11: Mar 18 '08

re: What is Operator ^+


Jack.Thomson.v3@gmail.com wrote:
Quote:
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
http://www.iedu.com/DeSoto/
rpgfan3233
Guest
 
Posts: n/a
#12: Mar 18 '08

re: What is Operator ^+


On Mar 18, 8:00*am, Jack.Thomson...@gmail.com wrote:
Quote:
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!
Jack.Thomson.v3@gmail.com
Guest
 
Posts: n/a
#13: Mar 19 '08

re: What is Operator ^+


On Mar 19, 2:53 am, rpgfan3233 <rpgfan3...@gmail.comwrote:
Quote:
On Mar 18, 8:00 am, Jack.Thomson...@gmail.com wrote:
>
>
>
Quote:
Why does the following program works, and what is ^+ operator ?
>
Quote:
int main()
{
int a = 10;
int b = 20;
int c;
>
Quote:
c = a ^+ b;
>
Quote:
printf("Value ===%d", c);
>
Quote:
return 0;
>
Quote:
}
>
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...
Closed Thread