因为:
1^0=1=(1+0)%2;
0^1=1=(0+1)%2;
0^0=0=(0+0)%2;
1^1=0=(1+1)%2;
设
a的二进制位为a1a2.....an
b的二进制位为b1b2....bn
c的二进制位为c1c2.....cn
则
a^b=(a1^b1)(a2^b2)......(an^bn)=(a1+a2)%2(a2+b2)%2......(an+bn)%2
a^b=b^a
(a^b)^c=a^b^c
相当于
(a1^b1^c1)(a2^b2^c2)......(an^bn^cn)
......
an表示a的二进制第n位
bn表示b的二进制第n位
cn表示c的二进制第n位
因为an^bn^cn=(an+bn)%2^cn=((an+bn)%2+cn)%2=(an+bn+cn)%2--(因为a%2%2=a%2)
又因为an^(bn^cn)=an^(bn+cn)%2=(an+(bn+cn)%2)%2=(an+bn+cn)%2
所以
an^bn^cn=an^(bn^cn)
所以
(a^b)^c=a^b^c=a^(b^c)
a^b^b=a^(b^b)=a^00......0=(a1^0)(a2^0)......(an^0)=(a1+0)%2(a2+0)%2......(an+0)%2=a1a2...an
a^b^a=b
应用:加密解密简单思路 |