21 lines
1008 B
Markdown
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

## 2.65
定义一次操作为将 $w$ 位的整数 $x$ 从中间分成两个 $\frac{w}{2}$ 位的整数 $y$ 和 $z$,接着令 `x=y^z`。进行该操作 5 次后得到答案。
我们将这样的思路称为“折半递归法”。
## 2.66
第一次操作,我们令 `x = x | (x >> 1)`,这样 $x$ 的最高位所在 `1` 连续段长度必然不小于 2。
第二次操作,令 `x = x | (x >> 2)`,依次类推。通过 5 次操作即可实现提示中的转换。
## 2.75
$x,y$ 是无符号整数,$x'=U2T_w(x),y'=U2T_w(y)$。
$$
\begin{aligned}
x'\times y'&=(x+x_{w-1}2^w)\times(y+y_{w-1}2^w)\\
&=x\times y+(x_{w-1}\times y+y_{w-1}\times x)2^w+x_{w-1}y_{w-1}2^{2w}
\end{aligned}$$
因此有 $U2B_{2w}(x'\times y')=T2B_{2w}(x\times y+(x_{w-1}\times y+y_{w-1}\times x)2^w)$。即令 `a = signed_high_prod(x, y), b = unsigned_high_prod(x', y')`$T2B_w(a+x_{w-1}\times y+y_{w-1}\times x)=U2B_w(b)$。
## 2.80
先得到粗糙的答案 `(x >> 2) + ((x >> 2) << 1)`,再根据 `x & 3` 进行修正。