A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
Win a copy of
Arduino in Action
this week in the
General Computing
forum!
A special promo:
Enter your blog post or vote on a blogger to be featured in an upcoming Journal
JavaRanch
»
Java Forums
»
Java
»
Java in General
Author
ShiftWise operator
Vidya Lakshman
Greenhorn
Joined: Apr 09, 2008
Posts: 10
posted
Aug 31, 2012 02:43:10
0
class Demo { public static void main(String a[]) { int i=-24 >>> 2; System.out.println(" >> opeartor"); System.out.println(" -24 >> 2 = " +( -24 >> 2)); System.out.println(" 24 >> 2 = " +( 24 >> 2)); System.out.println(" 24 >>> 2 = " +( 24 >>> 2)); System.out.println(" - 24 >>> 2 = " +( -24 >>> 2)); System.out.println("i" +Integer.toBinaryString(i)); } }
what is the output of the above code & explain the working?
Any help is highly appreciated.
Regards
Vidya
Ankit Dan
Ranch Hand
Joined: Aug 31, 2012
Posts: 47
I like...
posted
Aug 31, 2012 03:58:04
0
public static void main(String a[]) { int i = -24; System.out.println(" value of i :" + Integer.toBinaryString(i)); i = -24 >>> 2; System.out.println(" value of i :" + Integer.toBinaryString(i)); System.out.println(" >> operator"); i = -24 >> 2; System.out.println(" value of i : " + Integer.toBinaryString(i)); i = 24 >> 2; System.out.println(" 24 >> 2 = " +); i = 24 >>> 2; System.out.println(" value of i : " + Integer.toBinaryString(i)); i = -24 >>> 2 System.out.println(" value of i : " + Integer.toBinaryString(i)); }
this will help you analyse..
Matthew Brown
Bartender
Joined: Apr 06, 2010
Posts: 3865
1
I like...
posted
Aug 31, 2012 04:01:40
1
Vidya Lakshman wrote:
what is the output of the above code & explain the working?
The best way for you to find out the output would be to run it yourself.
So run it, and try and work out why the output is what it is. Then come back to us if you can't work it out, and we can help you.
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32833
4
posted
Aug 31, 2012 04:17:30
0
Why, on the other
thread
, did you think the 4th line gives a negative output?
I agree. Here's the link:
http://aspose.com/file-tools
subject: ShiftWise operator
Similar Threads
Want to convert my code in method
JSP Action Buttons freez after returning from ajax call
DHTML drop down menu - Cross Browser
iterate problem in struts2
enable/disable textbox
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter