• 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

how negative decimals represented in binary

 
Ranch Hand
Posts: 40
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can any body give me logic of
-5... how it will be represented in binary

in that case say
-5 >> 8 what is the result of this operation.
 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Java uses two's complement to represent negative nos.
u can represent 5 in binary as 00000101
so two;s complement of 5 will be -5 i.e frst invert all teh digits and then add 1 to it to get -5.
so -5 in binary will be 11111010 + 00000001 = 11111011

result of -5>>8 will be 1111 1111
 
Ranch Hand
Posts: 7729
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
May be this tipline article from Corey will help you understand.
 
arch rival
Posts: 2813
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have written some material about bit shifting (and thus number representation) at http://www.jchq.net/certkey/0501certkey.htm

Note that the JDK 1.5 (Java5/Tiger) exam does not cover bit shifting.
 
reply
    Bookmark Topic Watch Topic
  • New Topic