Java 中的“~”运算符是什么
What is "~" operator in Java
谁能帮忙解释一下Java中“~”的作用?我搜索了但找不到答案,因为我不知道 ~ 叫什么。提前致谢。下面是一个名为 Snow 的开源隐写程序的示例。
private int tabpos (int n) {
return ((n + 8) & ~7);
}
来自 Oracle 文档:
The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".
谁能帮忙解释一下Java中“~”的作用?我搜索了但找不到答案,因为我不知道 ~ 叫什么。提前致谢。下面是一个名为 Snow 的开源隐写程序的示例。
private int tabpos (int n) {
return ((n + 8) & ~7);
}
来自 Oracle 文档:
The unary bitwise complement operator "~" inverts a bit pattern; it can be applied to any of the integral types, making every "0" a "1" and every "1" a "0". For example, a byte contains 8 bits; applying this operator to a value whose bit pattern is "00000000" would change its pattern to "11111111".