Find the 2s complementary representation in 8bits of the num
Solution
To calculate the 2\'s complement of an integer, invert the binary equivalent of the number
by changing all of the ones to zeroes and all of the zeroes to ones (also called 1\'s complement), and then add one.
For example,
0001 0001(binary 17) such that
1110 1111(two\'s complement -17)
NOT(0001 0001) = 1110 1110 (Invert bits)
1110 1110 + 0000 0001 = 1110 1111 (Add 1)
->
1987 = 1024 + 512 + 256 + 128 + 64 + 2 + 1
1987 = 2^10 + 2^9 + 2^8 + 2^7 + 2^6 + 2^1 + 2^0
1987 base ten = 0000 0111 1100 0011 base two
-1987 is the two\'s complement of 1987.
To find the two\'s complement of a binary number, you first invert all of the digits (i.e. 1 becomes 0, and 0 becomes 1), and then add one to the result.
0000 0111 1100 0011 inverted is 1111 1000 0011 1100.
Adding one to this yields:
-1987 base ten = 1111 1000 0011 1101 (two\'s complement binary)
--------------------------------
To find -1987 in hex, first 1987 (hex) must be found.
1987 = 1792 + 192 + 3
1987 = 7*16^2 + 12*16^0 + 3*16^0
1987 base ten = 0007C3 hex
To find the 16\'s complement of a hex number, first you take the 15\'s complement by subtracting each digit from \'F\', then add 1.
0 -> F - 0 = F
0 -> F - 0 = F
0 -> F - 0 = F
7 -> F - 7 = 8
C -> F - C = 3
3 -> F - 3 = C
Adding one to this yields:
-1987 base ten = FFF83D (16\'s complement hex)
----------------------------------
To find -19575 in two\'s complement binary, first 19575 (binary) must be found.
19575 = 16384 + 2048 + 1024 + 64 + 32 + 16 + 4 + 2 + 1
19575 = 2^14 + 2^11 + 2^10 + 2^6 + 2^5 + 2^4 + 2^2 + 2^1 + 2^0
19575 base ten =(NNN) NNN-NNNN0111 0111 base two
To find the two\'s complement of a binary number, you first invert all of the digits (i.e. 1 becomes 0, and 0 becomes 1), and then add one to the result.
(NNN) NNN-NNNN0111 0111 inverted is(NNN) NNN-NNNN1000 1000
Adding one to this yields:(NNN) NNN-NNNN1000 1001 (two\'s complement)
It can be seen that in this conversion, the sign bit was lost due to overflow, since 15 bit two\'s complement has a range from -(2^13) to 2^13-1, or in decimal, -8192 to 8192.
Therefore, the computer thinks that it has the binary number:
0011 0011 1000 1001,
or in decimal:
2^13 + 2^12 + 2^9 + 2^8 + 2^7 + 2^3 + 2^0
8192 + 4096 + 512 + 256 + 128 + 8 + 1
13193 (decimal)

