Anonymous

Ranch Hand

Posts: 18944

posted 16 years ago

Hi all,

I got confused by the mock question:

int x1 = -1, x2 = -1; x1 = x1 >>> 31; x2 >>= 31;

what is the result:

a) x1 = -1, x2 = -1

b) x1 = 1, x2 = -1

c) x1 = 1, x2 = 1

d) x1 = 1, x2 = 0

I think none of is correct. x1=1 is correct, but x2 is not possiable to be -1, 1 or 0. For x2>>=31, the result should be 32 bits with all 1, Am I right? Please help me!

mike

I got confused by the mock question:

int x1 = -1, x2 = -1; x1 = x1 >>> 31; x2 >>= 31;

what is the result:

a) x1 = -1, x2 = -1

b) x1 = 1, x2 = -1

c) x1 = 1, x2 = 1

d) x1 = 1, x2 = 0

I think none of is correct. x1=1 is correct, but x2 is not possiable to be -1, 1 or 0. For x2>>=31, the result should be 32 bits with all 1, Am I right? Please help me!

mike

Anonymous

Ranch Hand

Posts: 18944

hemanshow

Greenhorn

Posts: 25

posted 16 years ago

x1 is 11111111111111111111111111111111 (32 1's )

x2 is 11111111111111111111111111111111 (32 1's )

x1 = x1 >>>31

x2 >>= 31;

now:

x1 = 00000000000000000000000000000001

x2 = 11111111111111111111111111111111

>>> adds o's to left.

>> adds what was already at the most significatnt bit(1's in our case)

M I right?

x2 is 11111111111111111111111111111111 (32 1's )

x1 = x1 >>>31

x2 >>= 31;

now:

x1 = 00000000000000000000000000000001

x2 = 11111111111111111111111111111111

>>> adds o's to left.

>> adds what was already at the most significatnt bit(1's in our case)

M I right?