JavaScript Program to Converter a Decimal to Binary
You are Here:
Converter a Number from Decimal to Binary
In the following example, we will convert a Decimal Number (500) to Binary Number (111110100).
Tips: It is recommended to use our online Decimal to Binary calculator for better understanding.
Example
HTML Online Editor
<!DOCTYPE html>
<html>
<body>
<h1>JS Decimal to Binary Converter</h1>
<script>
var num = 500;
var arr = [];
var i = -1;
var j;
while(num != 0)
{
i++;
arr[i] = num % 2;
console.log(arr[i]);
num = Math.floor(num / 2);
}
//reverse the array and display
for(j = i; j >= 0; j--)
document.write(arr[j]);
</script>
</body>
</html>
Reminder
Hi Developers, we almost covered 97% of JavaScript Tutorials with examples for quick and easy learning.
We are working to cover every Single Concept in JavaScript.
Please do google search for:
Join Our Channel
Join our telegram channel to get an instant update on depreciation and new features on HTML, CSS, JavaScript, jQuery, Node.js, PHP and Python.
This channel is primarily useful for Full Stack Web Developer.