Win a copy of Murach's MySQL this week in the JDBC and Relational Databases forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

casting - shift operators [scjp1.4]

 
Ranch Hand
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


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
Posts: 163
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic