^操作符在Java中做什么?是什么功能?^(卡雷特)操作员服务于Java?当我尝试这个:int a = 5^n;.它给了我对于n=5,返回0对于n=4,返回1对于n=6,返回3.所以我想它不会进行指数运算但那又是什么呢?
3 回答
HUH函数
TA贡献1836条经验 获得超4个赞
^
Operator Name Example Result Descriptiona & b and 3 & 5 1 1 if both bits are 1.a | b or 3 | 5 7 1 if either bit is 1.a ^ b xor 3 ^ 5 6 1 if both bits are different.~a not ~3 -4 Inverts the bits.n << p left shift 3 << 2 12 Shifts the bits of n left p positions. Zero bits are shifted into the low-order positions.n >> p right shift 5 >> 2 1 Shifts the bits of n right p positions. If n is a 2's complement signed number, the sign bit is shifted into the high-order positions.n >>> p right shift -4 >>> 28 15 Shifts the bits of n right p positions. Zeros are shifted into the high-order positions.
暮色呼如
TA贡献1853条经验 获得超9个赞
0 ^ 0 = 01 ^ 1 = 00 ^ 1 = 11 ^ 0 = 1
4 = 1 0 0 5 = 1 0 16 = 1 1 0
5 ^ 4 => 1 0 1 (5) 1 0 0 (4) ---------- 0 0 1 => 1
5 ^ 5 => 1 0 1 (5) 1 0 1 (5) ------------ 0 0 0 => (0)5 ^ 6 => 1 0 1 (5) 1 1 0 (6) ----------- 0 1 1 => 3
添加回答
举报
0/150
提交
取消