In Javascript when I do this
var num = 1;
~ num == -2
why does ~num not equal 0
in binary 1 is stored as 1 … thus not 1 should be 0
or it is stored like 0001 thus not 0001 would be 1110
I think I am missing something… can someone clear this up
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Look up Two’s complement for signed binary numbers
Lets assume that a javascript Number is 8 bits wide (which its not):
then
and
Which is the binary representation of
-2