On Wed, 23 Feb 2005, wrote: > So how do I take the complement of an unsigned number that has 1 as > the MSB? If I'm using an 8 bit system, and a = 10000101b = 133d, what > is a's complement? Is it 01111010? There are two terms: "two's complement representation" and applying "two's complement" operation (~a+1)=-a without worrying about the semantics of whether it is signed or unsigned. 10000101b = a 01111010b = ~a = one's complement + 1b --------- 01111011b = (~a+1) = two's complement =============================================== Some more questions about homework #4, second page: 1) The statement u = a - b. If a and b are both unsigned (they have to be if we're using 8 bits, since their values are between 127 and 255) and b is greater than a, how do I perform a subtraction here? The result is negative, but I'm working with unsigned numbers. In two's complement: u = a - b is the same as u = a + (~b + 1) Don't need subtract instruction. 2) Same question for s = w - x. The same as above. You will notice in the 8051 machine instructions that there are no signed add or unsigned add only add. The 8051 just add bits and does not care about semantics as a C compiler does. 3) Similarly, in s = ~w and s= -w, how do I get the complement if w is an unsigned number and the MSB is 1? ~w is always 1's complement. Again, once you have the bits just "not" them. And -w is ~w+1 4) For the last one, s = -z ^ ~a, I got a as the answer. Is this correct? Also, how would I code this in 8051? mov a,r6 ;regA=z; cpl a ;regA = ~regA add a,#1 ;regA = regA + 1 mov r3,a ;s=regA mov a,r0 ;regA=a cpl a ;regA=~regA xrl a,r3 ;regA=regA ^ s mov r3,a ;s=regA =============================================== > Could you explain the difference between big endian and little endian? > I understand that the one's complemement of 01100010 is 10011101 and yes > the two's complement is 10011111 (right?), no, 10011101 + 1 -------- 10011110 where 1+1 is Sum=0 and Carry=1 see page 32, table 2-3 but where do big endian and > little endian come into play with this? big "bit" endian is most significant bit first: dn-1 .... d3 d2 d1 d0 = 128+64+...+4+2+1 = 10011110 little "bit" endian is least significant bit first: d0 d1 d2 d3 .... dn-1 = 1+2+4+...+64+128 = 01111001 ============================================= --Prof. Wolff.