From a2630d663a1842d2b0baf51678565fed7919a438 Mon Sep 17 00:00:00 2001 From: ember <1279347317@qq.com> Date: Sat, 6 Sep 2025 01:51:11 +0800 Subject: [PATCH] =?UTF-8?q?=E5=A2=9E=E5=8A=A0=E5=86=85=E5=AE=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- content/post/算法题/位运算操作.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/content/post/算法题/位运算操作.md b/content/post/算法题/位运算操作.md index 34efb29..600099a 100644 --- a/content/post/算法题/位运算操作.md +++ b/content/post/算法题/位运算操作.md @@ -27,7 +27,8 @@ math: true | `x & 1` | 判断奇偶性:真为奇,假为偶 | | `(n > 0) && ((n & (n - 1)) == 0)` | 判断n是否为2的幂。因为2的幂的二进制只有一个1,用n & (n-1)可以直接把它唯一的1去掉变成0。 | `n & ((1 << k) - 1)` | 等价于 `n % (1 << k)`,即`n`对$2^k$取模 | -| `a ^= b; b ^= a; a ^= b` | 交换a和b的值 | +| `a ^= b; b ^= a; a ^= b;` | 交换a和b的值 | +| `~n` | 对n按位取反,结果为-n-1 | 统计二进制数中1的个数: ```cpp