int -int 2's comp 0000 0 0 0 0001 1 1 1 0010 2 2 2 0011 3 3 3 0100 4 4 4 0101 5 5 5 0110 6 6 6 0111 7 7 7 1000 8 -0 -8 1001 9 -1 -7 1010 10 -2 -6 1011 11 -3 -5 1100 12 -4 -4 1101 13 -5 -3 1110 14 -6 -2 1111 15 -7 -1 "int" is if we treat each value as unsigned (always positive) "-int" is if we use the left-most bit to indicate sign, with the other bits to represent magnitude "2's comp" is if we represent the numbers in 2's complement form. Using "-int": if -1 is 1001, and we add this to 2 0010, the result is 1011 which is "-3" under this representation. This makes no sense: -1 + 2 != -3 1001 0010 ------- 1011 Using "2's comp": -1 1111 add to 2 (0010), we get 0001 which is 1. This makes sense: -1 + 2 = 1 110 1111 0010 -------- 1 0001 To find the 2's comp : 1. find the 1's comp 2. add 1 e.g. to find -3, we start with 3 (0011) 1's comp : 1100 add 1 : 1101 ----------------------- Shift 00111001 shift left: 01110010 0011 shift left 0110 shift left 1100 dec 3 6 12 shift right: 0101 0010 0001 ----------------- convert 00111001 to dec 1x2^0 + 0x2^1 + 0x2^2 + 1x2^3 + 1x2^4 + 1x2^5 + 0x2^6 + 0x2^7 = 1x2^0 = 1 + 1x2^3 = 8 + 1x2^4 = 16 + 1x2^5 = 32 = 32 + 16 + 8 + 1 = 57 What if the binary value starts with 1 in the left-most bit? Find 2's complement, then do the above conversion, then remember to write the answer with a minus-sign. ----------------------------- OR Truth table a b| a OR b ------------- 0 0| 0 0 1| 1 1 0| 1 1 1| 1 XOR Truth table a b| a XOR b ------------- 0 0| 0 0 1| 1 1 0| 1 1 1| 0 AND Truth table a b| a AND b ------------ 0 0| 0 0 1| 0 1 0| 0 1 1| 1 NOT Truth table c| NOT(c) ------- 0| 1 1| 0