

- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
How do I convert an integer to binary in JavaScript?
To convert an integer to binary in JavaScript, divide the integer by 2 and store the remainder.
Example
Following is the code −
function convertDecimalToBinary(value) { var binaryValues = []; var counter = 0; while (value > 0) { binaryValues[counter++] = parseInt(value % 2); value = parseInt(value / 2); } for (var j = counter - 1; j >= 0; j--) process.stdout.write(binaryValues[j] + ""); } convertDecimalToBinary(5);
To run the above program, you need to use the following command −
node fileName.js.
Here, my file name is demo255.js.
Output
This will produce the following output on console −
PS C:\Users\Amit\javascript-code> node demo255.js 101
- Related Questions & Answers
- How do I convert a string into an integer in JavaScript?
- Convert an array of binary numbers to corresponding integer in JavaScript
- Java Program to convert an integer into binary
- Golang Program to convert an integer into binary representation
- C# program to convert binary string to Integer
- How do I empty an array in JavaScript?
- How do I check to see if a value is an integer in MySQL?
- How to convert a string of any base to an integer in JavaScript?
- How to convert a Boolean to Integer in JavaScript?
- How to convert Decimal to Binary in JavaScript?
- How to convert Binary to Decimal in JavaScript?
- How do I check that a number is float or integer - JavaScript?
- How to convert an integer to an ASCII value in Python?
- How do I convert a char to an int in C and C++?
- How to convert a string into integer in JavaScript?
Advertisements