Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
Java 中的“~”操作符有什么作用byte b =~5 + 1?
byte b =~5 + 1
当结果被发送到标准输出时,System.out.print(b)它会打印出来,'-5'但我不知道为什么或它代表什么。
System.out.print(b)
'-5'
它是按位补码运算符。由于 java 使用二进制补码来表示负数,~x + 1所以等价于-x.
~x + 1
-x