-4

what is this function used for ? and it's not for the power function. :

    #include<iostream>

    using namespace std;

    int main(){

    int x,y;

    cout<<(x^y)<<endl;/* this is the unkown (X^Y)*/

    return 0;

    }
Jeru Luke
  • 20,118
  • 13
  • 80
  • 87
Beeshoy Elshaype
  • 39
  • 1
  • 1
  • 6

3 Answers3

5

The ^ operator is the bitwise XOR. Take for example 6 and 12

6 in binary is: 110

12 in binary is: 1100

The xor follows this rule: "The first or the second but not both". What does it mean? Its truth table should make it clear:

A     B     A^B
0     0      0
0     1      1
1     0      1
1     1      0

You can see that the only 1-bits are those where or A or B (but not both) are set.

Back to the first example:

A    1100 => 12
B    0110 => 6
A^B  1010 => 10
Marco Luzzara
  • 5,540
  • 3
  • 16
  • 42
2

It's XOR. If you want more information about it see here https://en.wikipedia.org/wiki/Exclusive_or

Nikita Davidenko
  • 160
  • 2
  • 12
2

Power function in c++ is

#include <math.h>
#include <iostream>
int main()
{
    int x, y;
    std::cout << "Give numbers " << std::endl;
    std::cout << "x = ";
    std::cin >> x;
    std::cout << "y = ";
    std::cin >> y;
    std::cout << "Result = " << pow(x, y) << std::endl;
    return 0;

}

Your version is XOR (logical operation) which is used to for example embedded systems etc.

21koizyd
  • 1,843
  • 12
  • 25