[英]Boolean Logical not operator on Integer Java
是否有一个方法接受16位无符号整数,并对其执行布尔逻辑NOT运算。
The bitwise negation-operator is ~
. 按位求反运算符是
~
。 Example: 例:
int i = 6;
System.out.println(~i); // Prints -7
If you want to treat the integer as an unsigned 16-bit integer (ie disregard from the most significant 16 bits) you should do 如果你想将整数视为无符号的16位整数(即忽略最重要的16位),你应该做
public static int u16neg(int i) {
return ~i & 0xFFFF;
}
Example: 例:
System.out.println(u16neg(0b00000000_00000000_00000000_00000110)); // 65529
System.out.println( 0b00000000_00000000_11111111_11111001); // 65529
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.