-5 in computer VS in actual. 2's complement

5 = 00000101

-5 = ~5 + 1
= 11111010 + 1 = 11111011

But, 11111011 is not 5 in decimal. So what is -5 in binary ?

Hi @anuj_it you have correctly formulated -5 in binary i.e. 11111011 , i think you are confused in how computer percives negetive number

lets think like how a compter thinks when it recieves 00000101 and 11111011 (consider int as 8 bit number )

  1. when the computer gets 00000101 it checks its MSB( most significant bit i.e the leftmost bit) since the MSB tells the sign of number (0 for positive and 1 for negetive) thus the computer knows 00000101 is a positive number so it will calculate it as usual and we get 5 in decimal
    but things are interesting for negetive number
  2. when the computer gets 11111011 it check it MSB , which is 1 this means this number is a negetive number ,as the computer knows that the number is in 2’s compliment . thus it takes its 2’s compliment i.e 00000100+1 which is 00000101 which is 5 and puts a -ve sign with it . thus we get -5 as the result

In case of any doubt feel free to ask :slight_smile:
If you got the answer mark your doubt as resolved
if you liked the answer then hit a like :+1:

Ok… so 10000001 (binary form) would be a -ve number and not 129 ?

And if someone asks me what is binary of -5, so ans would be 11111011 ?
And if its written somewhere 11111011, so how will I come to know whether its -5 or 251 ?

by its most significant bit if 1 then its a negetive number and 0 then positive if we are dealing with 8 digit binary numbers than 11111011 then its -5 and if we are dealing with 32 bit number then it is 251

1 Like

I hope I’ve cleared your doubt. I ask you to please rate your experience here
Your feedback is very important. It helps us improve our platform and hence provide you
the learning experience you deserve.

On the off chance, you still have some questions or not find the answers satisfactory, you may reopen
the doubt.

I think that Oracle Exam Practice Test Questions is crucial for graduating from any university. Every student should know how to write and I think you should be able to do it, too. I would recommend you to take some extra classes or enroll in additional course.

The most common encoding of negative numbers in processors is not using 1’s complement but 2’s complement.

Using 2’s complement 00000101 is 5, but 11111010 means -6, not -5.

If we use the common addition rule we get 11111111 which is -1 as expected.

We can see it another way: if we were using 1’s complement for encoding negative numbers then what would be the opposite of zero (encoded as 00000000) ? Wouldn’t it be 11111111 ?
And if you want to more knowledge about it then you take some IT Courses that improve your knowledge about it. So get the latest ECCouncil 312-38 exam questions for free that stimulates a real Certified Network Defender with the right answers