473,395 Members | 1,502 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

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;
}
Mar 18 '08 #1
12 1536
Ja*************@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
Mar 18 '08 #2
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);

Mar 18 '08 #3
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.
Mar 18 '08 #4
In article <0a**********************************@u69g2000hse. googlegroups.com>,
John Bode <jo*******@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.

Mar 18 '08 #5
Ja*************@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
Mar 18 '08 #6
In article <1b**********************************@s8g2000prg.g ooglegroups.com>,
<Ja*************@gmail.comwrote:
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
Mar 18 '08 #7
Ja*************@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
es*****@ieee-dot-org.invalid
Mar 18 '08 #8
Ja*************@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:Th*************@gmail.com>

Mar 18 '08 #9
Ja*************@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:Th*************@gmail.com>
Mar 18 '08 #10
Ja*************@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
http://www.iedu.com/DeSoto/
Mar 18 '08 #11
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!
Mar 18 '08 #12
On Mar 19, 2:53 am, rpgfan3233 <rpgfan3...@gmail.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...
Mar 19 '08 #13

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

26
by: Steven Bethard | last post by:
I thought it might be useful to put the recent lambda threads into perspective a bit. I was wondering what lambda gets used for in "real" code, so I grepped my Python Lib directory. Here are some...
70
by: Roy Yao | last post by:
Does it mean "(sizeof(int))* (p)" or "sizeof( (int)(*p) )" ? According to my analysis, operator sizeof, (type) and * have the same precedence, and they combine from right to left. Then this...
9
by: John Cho | last post by:
// CHO, JOHN #include<iostream> class fracpri{ int whole; int numer; int denom;
3
by: John Cho | last post by:
/* This program is a database program that will store video tape names, minutes, year released, and price I want it to be professional so that *YOU* will want to buy it and use it for a video...
8
by: dru | last post by:
Every time I think I know or understand C++ with some confidence, I see something that changes that. I was looking at the boost shared_ptr docs and code, and I ran across the operator...
10
by: Steven T. Hatton | last post by:
I read Stroustrup's article of the day: http://www.research.att.com/~bs/C++.html Programming with Exceptions. InformIt.com. April 2001. http://www.research.att.com/~bs/eh_brief.pdf Some of...
17
by: Anoob | last post by:
Can we consider () unary operator when calling a function, in exps eq. f(), ( 1 + 2). But when we call function f( 10 ) it is a binary operator. Even if we pass f( 10, 20) as we are using ,...
2
by: stella_pigeon | last post by:
Can someone offer me a hint how to correctly program the problem outlined below? I have a template class defines as follows class A { int a1; int a2; operator == ... }
16
by: Ajay | last post by:
Hi all, i want to know when i create a class.what all it contains.I know the following things are there by default if i do not declare them by myself.Please tell the other things that are left. ...
2
by: Peng Yu | last post by:
Hi, In the following code, the 'copy' member function works. But the '=' operator does not work. Can somebody let me know why a member function is different from an operator. Thanks, Peng ...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.