Why is $-13$ represented as $11110011$ in binary?

598 Views Asked by At

Why is $-13$ represented as $11110011$ in binary? What's the logic behind this?

2

There are 2 best solutions below

0
On

I guess you mean why the complement code of -13 in 8-bit computer is 11110011.

  1. 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.
  2. 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.
1
On

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.