Meaningless Drivel is fun!*
The moose likes Programmer Certification (SCJP/OCPJP) and the fly likes casting - shift operators [scjp1.4] Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "casting - shift operators [scjp1.4]" Watch "casting - shift operators [scjp1.4]" New topic
Author

casting - shift operators [scjp1.4]

Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163


Hi
Meaning of line2 is,
caste i into byte - apply shift operator - print the result in binaryformat
line 1 + line3 does the same thing .
output of first two s.o.p() statements is same, then why line4 & line5 are displaying different values?
can any one of u explain me the reason?
Thanx in advance
[ December 28, 2005: Message edited by: Naresh Kumar ]
Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163
Hi
i hv got the solution.

System.out.println(b>>a);//line5
- here b is upcasted to int.
i=128 (decimal) = 10000000 (Binary)
b=(byte)i= 11111111111111111111111110000000 ( upcasting - all the leftside bits are filled with sign bit '1')

so b>>2 prints -32
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: casting - shift operators [scjp1.4]
 
Similar Threads
StringBuffer
capacity of a stringbuffer
Can you explain this ?
Feedback.
Need help in parsing text file with list to XML