22 Nov 2000 20:08
Re: two complement sum
> Somebody Knows why when using two complement sum of the pic ( and using Signed Aritimetic: bit 7 is the sign )
> adding 01 + FF the result is "00" instead the correct "FE"
> and adding C0 + 60 the result is "60" instead the correct "20"
> And have a subroutine or to do this? (signed 2's complement sum"
1)
0x01 = 1
0xFF = -1
1 + -1 = 0
2)
0xC0 = 0b11000000
0x60 = 0b01100000
Since the low nibble is 0, we can look at
C = 1100
6 = 0110
------
0010 + a carry bit
I get 0x20 for the answer, which may mean my binary is foggy.
Only in subtraction do you complement and add one.
--
D. Jay Newman !
jay@... ! Xander: Giles, don't make cave-slayer unhappy.
http://enerd.ws/robots/ !
--
(Continue reading)
RSS Feed