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

# simple question

Ranch Hand
Posts: 60
• Number of slices to send:
Optional 'thank-you' note:
can someone tell me how do i get the corresponding int value of this
1111111 111111111 11111111 11111010
-Thanks

Ranch Hand
Posts: 94
• Number of slices to send:
Optional 'thank-you' note:
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
• Number of slices to send:
Optional 'thank-you' note:
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
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
• Number of slices to send:
Optional 'thank-you' note:
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)
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