• 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
  • Tim Cooke
  • paul wheaton
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

how the -ve values organised

 
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi ranchers,
iam going towards scjp
but i got strucked at shifting operators
i didnot understood how the negative values are organised

for example

int b=-6;
String s=Integer.toBinaryString(b);
System.out.println(s);

output is :11111111111111111111111111111010

can anybody explain

thanx in advance

vijay
 
Ranch Hand
Posts: 336
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The toBinaryString method adds 2^32 to the value of the argument if its negative and then converts the value to a binary format. Add
2^32(2 to the power 32) + (-6) = 4 294 967 290.

Use the scientific calc on your computer to check the binary value.
 
Ranch Hand
Posts: 32
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
binary value of 6 : 00000000 00000000 00000000 00000110

for Negative value complement above and add 1(2's complement)

11111111 11111111 11111111 11111001 (complement of +6)
+ 1
----------------------------------------
equals 11111111 11111111 11111111 11111010 (2's complement of 6 ==-6)
[ March 13, 2006: Message edited by: srilatha reddy ]
 
kotha vijaybabu
Ranch Hand
Posts: 77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
hi....,

i got it
thanx all of u
 
My cellmate was this tiny ad:
Clean our rivers and oceans from home
https://www.kickstarter.com/projects/paulwheaton/willow-feeders
reply
    Bookmark Topic Watch Topic
  • New Topic