I am trying to convert decimal to binary numbers using AngularJS
let decimal = 128; let binary = parseInt(decimal.toString(), 2); // returning 1 You need to use toString() and not parseInt. This line of code work
let decimal = 128; var toBinary = (+decimal).toString(2); console.log(toBinary); try this simple way
(128).toString(2); //result is 10000000 <!DOCTYPE html> <html> <body> <p>Convert binary number from 128.</p> <button onclick="myFunction()">Try it</button> <p id="demo"></p> <script> function myFunction() { document.getElementById("demo").innerHTML = (128).toString(2); } </script> </body> </html>
decimalis already in binary.