1
console.log("0b111" ^ "0b001"); // 6
console.log(0b111 ^ 0b001); // 6

Though I can do this, is there any way to convert "0b111" to numeric literals 0b111 ? thanks.

11
  • 1
    Remove the quotes like you've done or use parseInt("0b111".slice(2), 2) if you need to do it programmatically. Commented May 28, 2020 at 18:29
  • Does this answer your question? How to convert binary representation of number from string to integer number in JavaScript? Commented May 28, 2020 at 18:32
  • const toBinaryFormat = (n) => `0b${n.toString(2)}` , and then toBinaryFormat(6) ==> "0b110". Commented May 28, 2020 at 18:33
  • thanks, but parseInt("0b111".slice(2), 2) will return 7 which is decimal, not a binary literal Commented May 28, 2020 at 18:40
  • 2
    "numeric literal" is "6". that is how console displays numbers. \x0001 and 0b111 are syntax representations of a number. what you are trying to ask for isn't possible and doesn't really make sense Commented May 28, 2020 at 18:47

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.