39 lines
1.3 KiB
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
第 $k$ 次操作,令 `x = x | (x >> (1 << (k - 1)))`。通过 5 次操作即可实现提示中的转换。
## 2.75
$x,y$ 是补码数,$x'=T2U_w(x),y'=T2U_w(y)$。
$$
\begin{aligned}
x'\cdot y'&=(x+x_{w-1}\cdot 2^w)\times(y+y_{w-1}\cdot 2^w)\\
&=x\cdot y+(x_{w-1}\cdot y+y_{w-1}\cdot x)2^w+x_{w-1}\cdot y_{w-1}\cdot 2^{2w}
\end{aligned}$$
进一步,令 `a = signed_high_prod(x, y), b = unsigned_high_prod(x', y')`,有
$$b\cdot 2^w+x'*^u_w y'=a\cdot 2^w+T2U_w(x*^t_wy)+(x_{w-1}\cdot y+y_{w-1}\cdot x)2^w+x_{w-1}\cdot y_{w-1}\cdot 2^{2w}$$
化简得
$$b=a+x_{w-1}\cdot y+y_{w-1}\cdot x+x_{w-1}\cdot y_{w-1}\cdot 2^w$$
$$\begin{aligned}
b&=(a+x_{w-1}\cdot y+y_{w-1}\cdot x)\bmod 2^w\\
&=T2U_w(a)+^u_t x_{w-1}\cdot y'+^u_t y_{w-1}\cdot x'
\end{aligned}$$
## 2.80
$$
\texttt{threefourths(x)}=\left\{\begin{aligned}
&3\cdot\lfloor x/4\rfloor+x\bmod 3-[x\bmod 3\neq0], &x\ge0\\
&3\cdot\lfloor x/4\rfloor+x\bmod 3, &x<0
\end{aligned}\right.
$$
## 2.97
在某些情况下舍入会导致最高位提高一位对于这种情况我们要将舍入时的最低有效位相应提高一位