I need to do bitwise OR of two binary strings.
For example, if the binary strings are '110001' and '101101', then I need the result as '111101'.
I tried this, but it gave me strange results.
console.log(110001 | 101101); You can't write binary numbers as literals in JavaScript. The only numeric literals allowed are:
1337 (One thousand and thirty-seven).02471 (One thousand and thirty-seven in base 8).0x539 (One thousand and thirty-seven in base 16).To write binary numbers you need to use parseInt with base 2. To convert a number to binary representation you use toString with base 2. Hence you would write it as:
var a = parseInt("110001", 2); var b = parseInt("101101", 2); var c = a | b; console.log(c.toString(2)); Simple.
console.log((parseInt("110001", 2) | parseInt("101101", 2)).toString(2))?