File APIs for Java Developers Manipulate DOC, XLS, PPT, PDF and many others from your application. http://aspose.com/file-tools
Big Moose Saloon
 Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies Register / Login

# Negative Numbers in Bits

L Sol
Greenhorn

Joined: Mar 23, 2004
Posts: 3
How do you calculate the following number is equal to -6?
1111 1111 1111 1111 1111 1111 1111 1010
Thanks!
Richard Quist
Ranch Hand

Joined: Feb 18, 2004
Posts: 96
Originally posted by L Sol:
How do you calculate the following number is equal to -6?
1111 1111 1111 1111 1111 1111 1111 1010
Thanks!

Since negative numbers are represented in two's-complement form you need to
• Flip all the bits
• restore the negative sign

• original: 1111 1111 1111 1111 1111 1111 1111 1010
inverted: 0000 0000 0000 0000 0000 0000 0000 0101
0001
----
0110 (which is 6 in base 10)
Restore negative sign: -6

Rich
SCJP 1.4
Serghei Jelauc
Ranch Hand

Joined: Jul 24, 2002
Posts: 128
Let say we have 1111 1101
Change all 1 and 0 vice versa: 0000 0010
0000 0010 = 2.
After it add 1: now have 3
That's all.
Hope it halps

SCJP 1.4 <br />SCBCD 1.3<br />SCWCD 1.4
Corey McGlone
Ranch Hand

Joined: Dec 20, 2001
Posts: 3271
If you want more information regarding 2's complement, do a search over this forum - you'll find tons of good information.
Corey

SCJP Tipline, etc.

I agree. Here's the link: http://aspose.com/file-tools

subject: Negative Numbers in Bits