• 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

Shift Bit (Negative Number)

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


the code prints

-7<<3. 11111111111111111111111111001000
-7<<3. -56


how does 11111111111111111111111111001000
translate to -56

thanks,
Shivani.
[ September 09, 2005: Message edited by: Shivani Chandna ]
 
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Shivani ,
Here Negative numbers are repersented by 2's complement numbers.. since sign bit is setted as 1 ..to get the actual value , we have to take complemet the given bit pattern and we have to add 1

for example
11111111111111111111111111001000 's
complement is
00000000000000000000000000110111 and add 1
00000000000000000000000000000001
--------------------------------------
00000000000000000000000000111000 which is equal to 56 ..since sign bit is 1 the value is -56 ..

Hope this helps for more clarification pls refer
http://www.janeg.ca/scjp/oper/shift.html


Regards
Prasanna
scjp 1.4
 
Shivani Chandna
Ranch Hand
Posts: 380
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
thanks Prasanna
 
author
Posts: 9050
21
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
and again... for those of you keeping count...

this is only a 1.4 topic - this topic isn't on the SCJP 5 exam
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic