Before I start, please don't tell me not to use eval
; I know the input is perfectly sanitary, so it's safe, fast, and easy.
I'm using a JavaScript engine to power a calculator I've written in Java. To do this, I simply concatonate input into a string and pass it to JavaScript. For instance, clicking the buttons 1
, +
, and 5
results in building the String "1+5"
. I got this working for hexadecimal, too, by putting 0x
before the letters, so A
, +
, and 8
gives me "0xA+8
. My problem comes from programming its binary mode. I tried passing it 0b1101+0b10
(which is how Java does binary literals), but it just throws an error. How do I handle binary literals in JavaScript?