following this Q&A I tried to exam the answer so I wrote:
#include <stdio.h>
int main ()
{
int t;int i;
for (i=120;i<140;i++){
t = (i - 128) >> 31;
printf ("t = %X , i-128 = %X , ~t & i = %X , ~t = %X
", t, i-128 , (~t &i), ~t);
}
return 0;
}
and the Output is:
t = FFFFFFFF , i-128 = FFFFFFF8 , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFF9 , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFFA , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFFB , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFFC , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFFD , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFFE , ~t & i = 0 , ~t = 0
t = FFFFFFFF , i-128 = FFFFFFFF , ~t & i = 0 , ~t = 0
t = 0 , i-128 = 0 , ~t & i = 80 , ~t = FFFFFFFF
t = 0 , i-128 = 1 , ~t & i = 81 , ~t = FFFFFFFF
t = 0 , i-128 = 2 , ~t & i = 82 , ~t = FFFFFFFF
t = 0 , i-128 = 3 , ~t & i = 83 , ~t = FFFFFFFF
t = 0 , i-128 = 4 , ~t & i = 84 , ~t = FFFFFFFF
t = 0 , i-128 = 5 , ~t & i = 85 , ~t = FFFFFFFF
t = 0 , i-128 = 6 , ~t & i = 86 , ~t = FFFFFFFF
t = 0 , i-128 = 7 , ~t & i = 87 , ~t = FFFFFFFF
t = 0 , i-128 = 8 , ~t & i = 88 , ~t = FFFFFFFF
t = 0 , i-128 = 9 , ~t & i = 89 , ~t = FFFFFFFF
t = 0 , i-128 = A , ~t & i = 8A , ~t = FFFFFFFF
t = 0 , i-128 = B , ~t & i = 8B , ~t = FFFFFFFF
Why does ~t
of any negative number is -1 == 0xFFFFFFFF
if t
declared as integer ?
See Question&Answers more detail:
os