-1 in binary representation

why is -1 's binary representation is all ones(11111111111)?

hi @varu, since the most significant bit is 1 , thus the we know that it represents a negative number
and we know that -ve number is represented in 2’s complement form so , to get the magnitude we have to find its 2’s complement which is (000000000+1) which is 1 and since the number is negetive we get -1 as output

In case of any doubt feel free to ask :slight_smile:
mark your doubt as resolved if you got the answer

ok,if we have for 7 we should write 0111 as binary representation and 111 is incorrect?

it should be mentioned that whether int is 8-bit,16 bit or 32-bit size (32 by default) ,accordingly you can set the most significant bit