Why 10^1 is 11?

前端 未结 6 600
不思量自难忘°
不思量自难忘° 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:42

    No! Do you think that is the power? Don't forgot this (In C++ and some of the programming languages): enter image description here

    Be sure to read this:

    • Operators (cplusplus)

    • Bitwise operation (wikipedia)


    A bitwise XOR takes two bit patterns of equal length and performs the logical exclusive OR operation on each pair of corresponding bits. The result in each position is 1 if only the first bit is 1 or only the second bit is 1, but will be 0 if both are 0 or both are 1. In this we perform the comparison of two bits, being 1 if the two bits are different, and 0 if they are the same. For example:

        0101 (decimal 5)
    XOR 0011 (decimal 3)
      = 0110 (decimal 6)
    

    The bitwise XOR may be used to invert selected bits in a register (also called toggle or flip). Any bit may be toggled by XORing it with 1. For example, given the bit pattern 0010 (decimal 2) the second and fourth bits may be toggled by a bitwise XOR with a bit pattern containing 1 in the second and fourth positions:

        0010 (decimal 2)
    XOR 1010 (decimal 10)
      = 1000 (decimal 8)
    

    This technique may be used to manipulate bit patterns representing sets of Boolean states.

    Source: Wikipedia

提交回复
热议问题