87
1
1111 1000 ------ 0111 0001 ------ 1000
300 sir
3
8-bit 2s complement representation of -19 is 11101101 For 1s complement invert all the bits. For 2s complement add 1 to the 1s complement: With 8-bits: 19 � 0001 0011 1s � 1110 1100 2s � 1110 1100 + 1 = 1110 1101
(1234)hex=(0001 0010 0011 0100)2 (DA57)hex=(1101 1010 0101 0111)2 Taking, (1234)hex=(0001 0010 0011 0100)2 =(1110 1101 1100 1011) -1s complement =(1110 1101 1100 1100) -2s complement Now ,add 2s complement of (1234)hex with (DA57)hex, we get 1110 1101 1100 1100 + 1101 1010 0101 0111 1 1100 1000 0010 0011 There is a Carry bit Since,carry is generated.so,no is negative Then take 2s complement of above no.Thus ,we get 0011 0111 1101 1101=(37DD)hex (1234)hex -(DA57)hex =37DD)hex
To get the 2s complement, find the 1s complement (by inverting the bits) and add 1. Assuming that number is [4-bit] binary it would be 1000. If it is preceded by 0s, as in, for example, 0000 1000, then it would be 1111 1000.
87
1
1111 1000 ------ 0111 0001 ------ 1000
-123 = 11 1000 0101 [I presume the number 123 is in decimal] First write the positive number in binary using 10 bits (I've split it into groups of 4 bits to make it easier to read): 123 = 00 0111 1011 Convert to 1s complement by inverting all bits (any 0 => 1, any 1 => 0): 00 0111 1011 => 11 1000 0100 Finally add 1 to get 2s complement: 11 1000 0100 + 1 = 11 1000 0101 Thus the 2s complement of the negative number: -123 = 11 1000 0101 This can also be expressed in hexadecimal: -123 = 0x385 Or in octal (easy to convert if the binary number is first written in groups of 3 bits): -123 = 1 110 000 101 = 01605 [I've used C notation for the hexadecimal and octal numbers.]
-15 is 11111111 and 2s com is 1111 0001
300 sir
First, write each number in binary form:DAB7 = 1101 1010 1011 01115634 = 0101 0110 0011 0100Now take the two's complement of 5634 in two steps:1's complement: 1010 1001 1100 1011Add 1 to make the 2's complement: 1010 1001 1100 1100Now add to find your result:1101 1010 1011 0111 + 1010 1001 1100 1100 = 1000 0100 1000 0011And write the result in hex:8483This works because the two's complement is the negative of the original number.
You can detect overflow if the result turns out to be negative (which is the same as checking to see if the sign bit is 1). For example if you tried to add 5 and 6 in to 4-bit 2s complement, you would get 0101 + 0110 = 1011, which is a negative number since the sign bit (the 1 on the left) is a 1. This is an overflow.
1101 => 11011 1010 => 10110 0011 => 10101 0001 => 01001 1000 => 10010 1001 => 10011 and together: 11011 10110 10101 01001 10010 10011