How to find the binary value of a negative number?

1. Decimal negative numbers are represented in binary

Here everyone must know that negative decimal numbers are represented in binary in two's complement form.

1.1 . Find the original code

Come on -5, practice brings true knowledge. Remove the negative sign first and convert 5 into binary byte form. Get 101, then add zeros.

Original code: 1000 0101

1.2 . Find the complement code

Then, negate (0 becomes 1, 1 becomes 0.)

The original code is as above: 1000 0101.

The first bit is the sign bit, which remains unchanged, and the other bits are inverted.

The inverse code is: 1111 1010 

1.3 . Find the complement code

Then, add one to get the complement (one's complement plus one is called the complement)

The final representation of -5 in the computer is 1111 1011.

1.4 , results

The two's complement code is the binary representation of negative numbers in computers. Then, 11111011 represents 8-bit -5. If you want to represent 16-bit -5, just add 8 1s on the left.

2. Two's complement binary returns negative decimal

So, if you know a negative number, you already know how to find the binary number. If you know a binary number, how do you find its decimal number? (For negative numbers) Just find a negative binary number.

2.1 . Obtain the complement code based on the complement code 

First subtract one and do the opposite of the above method. //Didn’t the above add one at the end? Then subtract one now.

2.2 . Obtain the original code based on the inverse code

Negation, wasn’t it negated above? It is also negated here.

2.3 . Results

So, the next step is to calculate. The calculation result is 13, then the binary number is: -13.

Guess you like

Origin blog.csdn.net/m0_50370837/article/details/119059097