解答

bitXor

要求

x^y using only ~ and &.

思路

XOR 需要相同为 1，不同为 0，而 AND 仅有 1 & 1 = 1

tmin

要求

Return minimum two’s complement integer.

isTmax

要求

Returns 1 if x is the maximum, two’s complement number, and 0 otherwise.

allOddBits

要求

Return 1 if all odd-numbered bits in word set to 1. (where bits are numbered from 0 (least significant) to 31 (most significant))

Return -x.

isAsciiDigit

要求

Return 1 if 0x30 <= x <= 0x39 (ASCII codes for characters ‘0’ to ‘9’).

conditional

要求

Same as x ? y : z.

isLessOrEqual

要求

If x <= y then return 1, else return 0.

思路

$x \le y \Rightarrow y - x \ge 0$.

logicalNeg

要求

Implement the ! operator, using all of the legal operators except !.

howManyBits

要求

Return the minimum number of bits required to represent x in two’s complement.

floatScale2

要求

Return bit-level equivalent of expression 2*f for floating point argument f. Both the argument and result are passed as unsigned int’s, but they are to be interpreted as the bit-level representation of single-precision floating point values. When argument is NaN, return argument.

floatFloat2Int

要求

Return bit-level equivalent of expression (int) f for floating point argument f.

floatPower2

要求

Return bit-level equivalent of the expression 2.0^x (2.0 raised to the power x) for any 32-bit integer x.

思路

• $e > 0$，判断是不是 INF，然后移位就好了。

• $e \le 0$，需要判断能否用 denorm 表示。

感想

dlc 和 btest 工具很好用！