【发布时间】:2015-06-16 22:53:24
【问题描述】:
这些不是作业,也不是家庭作业。 我正在准备我的中试。我需要有人告诉我哪个是正确的答案,并向我详细解释原因。
[2 marks] Given an unsigned integer n, the operation (n & ~1) will produce
(a) the value n mod 4
(b) n with its least significant bit cleared (i.e. set to 0)
(c) the value 2n
(d) the value n/2
(e) the least significant bit of n
[1 mark] Given an unsigned integer n, the operation (n << 1) will produce
(a) n with its least significant bit cleared (i.e. set to 0)
(b) the value n mod 4
(c) the value n/2
(d) the least significant bit of n
(e) the value 2n
不知道下面的2个公式能否帮你解决问题:
if (c & 0x1 == 0x1)~c = c OR c-1 //odd colour value),
if (c & 0x1 == 0x0)~c = c OR c+1 //even colour value.
【问题讨论】:
-
嗯。在我看来,第二个问题需要“以上都不是”的答案。 (例如,考虑
n = 2147483648在无符号整数为 32 位的系统上的情况。) -
@MarkDickinson,建议的数字(= 0x80000000)在左移一位时将导致进位为 1,其余数字为 0,即 '2n' 因此答案(e)是正确的