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;
} | | | | re: What is Operator ^+ Jack.Thomson.v3@gmail.com writes: Quote:
Why does the following program works, and what is ^+ operator ?
There is no operator ^+ but there is an unary operator + (like there an
unary operator -) which you are using here.
Yours,
--
Jean-Marc | | | | 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); | | | | 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. | | | | 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. | | | | 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 | | | | 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 | | | | 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 | | | | 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> | | | | 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> | | | | 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/ | | | | 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! | | | | 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:
printf("Value ===%d", c);
> > >
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... |  | | | | /bytes/about
We are a network of experts and professionals in IT and software development that help one another with answers to tough questions and share insights.
Get the best answers to your questions from over 226,510 network members.
|