^ in Python

I remembered when I started to learn Python, about 1 year ago, I often get confused with ^ and **.
With my poor computer basics, I often type ^ when I was trying to explain power, and I found out the output is quite strange. Later on, I just memorized ** and never asked about ^.
Until today, I finally solved the mystery.

The Outputs When I Use ^

^ represents XFOR in python, which add two integers in binary system with limited digits.

For example, when the computer do 4^1, it first converts the two numbers into binary numbers, which are 100 and 1. Secondly, it calculate 100 + 1 = 101, which is 5.
However in the third case, when the computer add 110 + 110, the result is 000. Thats because, when the programmer inputs 6^6, the computer automatically sets the binary digits of answer into the highest binary digits of input number. As the highest digits of the input number is 3, the value of the results is out of limits, which is called overflow. In the end, computer ouput the results of 000 in binary, which is 0

Leave a comment