Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# shift

josephine chen
Ranch Hand

Joined: Oct 29, 2002
Posts: 216
The following code will print
1: int i = 1;
2: i <<= 31; 1*2^31 = 2^31<br /> 3: i >>= 31; 2^31 /2^31 = 1
4: i >>= 1; 1>>=1 1/2 === 0
5:
6: int j = 1;
7: j <<= 31; 1*2^31<br /> 8: j >>= 31; 2^31/2^31 ==1
9:
10: System.out.println("i = " +i );
11: System.out.println("j = " +j);
A) i = 1
j = 1
B) i = -1
j = 1

C) i = 1

D) i = -1
j = -1
josephine chen
Ranch Hand

Joined: Oct 29, 2002
Posts: 216
where am i going wrong
Jim Yingst
Wanderer
Sheriff

Joined: Jan 30, 2000
Posts: 18671
For a problem like this, it's useful to print out intermediate results so that you can see for yourself if you're on the right track:

[This message has been edited by Jim Yingst (edited February 22, 2000).]

"I'm not back." - Bill Harding, Twister
Jane Rozen
Ranch Hand

Joined: Feb 12, 2000
Posts: 53
For those who search for "shift" on this forum - make sure you follow Jim's advice - check the result!
Hint:it will be D) i=-1, j=-1 .

I agree. Here's the link: http://aspose.com/file-tools

subject: shift