Why is this:
console.log("1100" ^ "0001")
=> 1101 // as expected
console.log("1100" ^ "1001")
=> 1957 // ???
Please explain. Thanks.
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.
Those numbers are interpreted as decimal numbers.
Try:
Of course the answer (0101) is printed in decimal (5).
The JavaScript token grammar supports numbers in decimal, octal, and hex, but not binary. Thus:
The first one worked, by the way, because 1100 (decimal) is 1101 (decimal) after the xor with 1.