File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
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
JavaRanch » Java Forums » Certification » Programmer Certification (SCJP/OCPJP)
Bookmark "casting - shift operators [scjp1.4]" Watch "casting - shift operators [scjp1.4]" New topic

casting - shift operators [scjp1.4]

Naresh Gunda
Ranch Hand

Joined: Oct 15, 2005
Posts: 163

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
i hv got the solution.

- 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
I agree. Here's the link:
subject: casting - shift operators [scjp1.4]
It's not a secret anymore!