Truncated match.
PICList
Thread
'Twos Compliment'
1995\10\29@151924
by
Eric Seeley
A simple way to determine the two's compliment equivalent of a number is :
Start with the original, straight binary representation of the positive
number, scan to the left leaving all digits unchanged untill the first 1 is
encountered. Leave this one unchanged and invert the rest of the digits to
the left.crossing the radix point has no effect.
Ex:
2d =0000 0000 0000 0010 2d=1111 1111 1111 1110 (d is for decimal)
32767=0111 1111 1111 1111 32767=1000 0000 0000 0001
not that the left most bit is sign (0 for positive 1 for negative)
The same result can be obtained by inverting the positive binary value and
then adding one:
+2d= 0000 0000 0000 0010
Invert: 1111 1111 1111 1101
Add 1 : 0000 0000 0000 0001
result: 1111 1111 1111 1110
Eric
1995\10\30@162425
by
John Payson

> A simple way to determine the two's compliment equivalent of a number is :
> Start with the original, straight binary representation of the positive
> number, scan to the left leaving all digits unchanged untill the first 1 is
> encountered. Leave this one unchanged and invert the rest of the digits to
> the left.crossing the radix point has no effect.
Three: 0011
3 : 1101
When you say "simple", it may be reasonably simple for a person, but it's
much more complex for a computer than n = ~n + 1. On the other hand, it is
useful to recognize that increment and decrement are really:
increment: toggle the rightmost zero and all the ones to its right
decrement: toggle the rightmost one and all the zeroes to its right
The definition you give for complementing corresponds with either (decrement
then flip all the bits) or (flip all the bits then increment).
Note that these definitions can be useful for operations such as "find the
rightmost one" [ lsb(n) = (n & ~(n1)) ] or find the rightmost zero [ lsz(n)
= (~n & (n+1)) ] .
More... (looser matching)
 Last day of these posts
 In 1995
, 1996 only
 Today
 New search...