Why 10^1 is 11?

前端 未结 6 594
不思量自难忘°
不思量自难忘° 2020-12-11 16:13

I am currently learning C++. I was trying to compute power of an integer using the expression:

val=10^1;

Instead of expected answe

6条回答
  •  我在风中等你
    2020-12-11 16:47

    Because ^ is the exclusive or operator and not the exponentiation operator. Basically, because the last bit of 10 in binary is 0, by applying exclusive or of 1 the last bit gets converted to 1 because it is different than 0.

提交回复
热议问题