• 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
  • Liutauras Vilda
  • Paul Clapham
Sheriffs:
  • paul wheaton
  • Tim Cooke
  • Henry Wong
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Piet Souris
Bartenders:
  • Mike London

simple question

 
Ranch Hand
Posts: 60
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can someone tell me how do i get the corresponding int value of this
1111111 111111111 11111111 11111010
-Thanks
 
Ranch Hand
Posts: 94
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
you know 1111....1111 (32 1's) is -1, right?
then,
-2: 1111....1110
-3: 1111....1101
-4: 1111....1100
-5: 1111....1011
-6: 1111....1010
 
Bartender
Posts: 2205
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That way works. But you can also remember that negative nubers are stored in two's compliment form. To find the value of a signed binary number with a negative sign, take the compliment of the number and add one. (The compliment means, make all the 1's zero, and make all the 0's one)
so the two's compliment of
1111111 111111111 11111111 11111010
is
00000000 00000000 00000000 00000101
adding one makes it
00000000 00000000 00000000 00000110
This is 6 in decimal. The number was originally negative, so we know this is a minus-6.
Rob
 
Ranch Hand
Posts: 417
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
first look at it: MSB is 1. ok so it got to be a negative number.
second all negative numbers are represented by 2's complement
how to recover a number from 2's complement:
invert all bits (make 1 into 0 and 0 to 1)
and add one
that's it.
111...............1010
invert it---> 00000....0101
add 1-------> 00000....0110 which is 6
we know it was negative so answer is -6

Originally posted by Arsho, Ayan:
can someone tell me how do i get the corresponding int value of this
1111111 111111111 11111111 11111010
-Thanks

 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic