经典指数          
原因
1508
浏览数
0
收藏数
 

If you computed 32 bit signed integers F and G from 32 bit signed X using F = X / 2 and G = (X>>1), and you found F!=G, this implies that
  • There is a compiler error
  • X is odd
  • X is negative
  • F - G = 1
  • G - F = 1

     举报   纠错  
 
切换
1 个答案

右移和除以2

对于正数的运算得到的结果是一样的,因为最低位被忽略,所以奇数还是偶数无关,结果相等;

对于负数,奇数结果不相等,偶数是结果相等的;而且算出来的结果必然是 

F = X / 2  大于 G = (X>>1),相差也只能是1;

综述,

X is negative 并且

X is odd; F-G=1.

 
切换
撰写答案
扫描后移动端查看本题