View Single Post
  #5 (permalink)  
Old February 5th, 2009, 02:33 PM
Babmi1960 Babmi1960 is offline
Registered User
 
Join Date: Feb 2009
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Default Convert 2's complement to decimal

If the number is positive then the binary representation is the number
eg 111 = 7, 101 = 5 etc ...
if the number is negative the most signigicant bit will be set to a one
if the word is a 16 bit integer then bit 15 will be set to 1 -

You need to flip all the bits that are one to 0 and all the bits that are 0 to 1's

eg: 1111 1111 1111 0110
flip 0000 0000 0000 1001 = 9

add 1
=10
and make it negative

-10

Or

1111 1111 1111 0110

Exclusive Or with

1111 1111 1111 1111

0000 0000 0000 1001

add 1

and make negative


Hope that helps!
Reply With Quote