Why is $-13$ represented as $11110011$ in binary? What's the logic behind this?
Asked
Active
Viewed 597 times
0
-
https://en.wikipedia.org/wiki/Two%27s_complement – gt6989b Oct 07 '20 at 13:48
-
1You should also clarify whether or not one of these bits is a sign bit and/or if we are referring specifically to arithmetic in $\Bbb Z_{2^8}$. Without context, I would have said that $11110011$ interpreted as a binary number is in fact is the positive integer $243$ when written as base 10. – JMoravitz Oct 07 '20 at 13:59
-
1Now... we do have that $11110011+00001101 = \color{red}{1}00000000$ and in the context of $\Bbb Z_{2^8}$ one does have that $11110011 + 00001101 = 00000000$ since that red "carry digit" gets lost since it is too far to the left and we can only keep track of eight bits at a time. So, in that sense... yes $11110011$ is the additive inverse of $00001101$... You have that $11110011$ is simultaneously $243$ as well as the additive inverse of $13$ – JMoravitz Oct 07 '20 at 14:02
-
1This is not really representation in binary, this is the representation in a particular computer format for signed integers. – Michal Adamaszek Oct 07 '20 at 14:19
2 Answers
1
I guess you mean why the complement code of -13 in 8-bit computer is 11110011.
- We already know that in computers, all data ends up being expressed in binary numbers. For the binary source code of signed numbers, the highest bit represents the sign, 0 is positive and 1 is negative. And the other digital bits represent the digital representation of the absolute value of the value itself. Then we can use 10001101 to represent -13. However, the computation rules of source code are complex. For example, if two numbers are added, the sign of the two numbers must be judged first. If the signs are the same, addition can be done. If the signs are different, the subtraction should be done. The sign of the sum is the same as the sign of the larger absolute value. The same is true for subtraction of two numbers. First, we must determine the sign of the two numbers, and then decide whether to add or subtract. The sign of the difference between the two numbers is also determined according to the size and sign of the two numbers.
- Then we have Inverse Code and Complement Code. The inverse code representation rule is: if it is a positive number, the representation method is the same as the original code; if it is a negative number, the sign bit remains unchanged, and the remaining bits are inverted, the inverse code representation of this number is obtained. For example, the reverse code of -13 in 8-bit computer is: 11110010. Complementary code is a general way for computers to represent data. The rule is: if it is a positive number, the representation method is the same as the original code; if it is a negative number, add 1 to the inverse of the number (equivalent to inverting the value of the original code and then Add 1 to the lowest bit. Then we have the 11110011.
Qiang Wang
- 11
- 1
1
A short answer is that the machine is doing integer arithmetic modulo 256. The binary pattern 11110011 equals decimal 243, which is the same as -13 modulo 256. In this scheme all binary patterns starting with 1 are presented to the user as negative numbers.
PMar
- 11
-
Your answer looks good, but I am not familiar with modulo arithmetic. – Cognoscenti Oct 07 '20 at 17:36