whether the bits are stored in 2’s or 1’s complement form in the computer memory?
sir has said in the video
~0=11111111
as ~0=1
so it will be written as 00000001
so,why sir has written like above?
whether the bits are stored in 2’s or 1’s complement form in the computer memory?
sir has said in the video
~0=11111111
as ~0=1
so it will be written as 00000001
so,why sir has written like above?
hi @Gurjot, if a number is negative then its stored in 2’s complement form .
~0 is not 1 , ~0=1111111111
i think you are confusing (~)(negation) and (!)(not) operations
~
takes each bit in a number and toggles it
!0
is 1
, !anythingElse
is 0
refer this for some examples on how 2’s complement work
int n= -1
it’s 1’s compliment==11111110, as the MSB is 1, computer will takes it’s 2’s compliment which is equal to
000000010 i.e 2, but the program gives the output 0.Why is this happening
in computer a negative number is stored as 2’s compliment of its positive conterpart
so -1 will be stored as 2’s complement of 1 which is 111111111111110+1=111111111111
and what computer does when it recieves 11111111111111 it checks its MSB which is 1 thus a negetive number so it takes its 2’s complement which is 00000000000+1=0000000001 and adds a negetive sign to it
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.