DECIMAL TO BINARY CONVERSION javascript
var n = 5;
n.toString(2); // "101"// program to convert decimal to binary
function convertToBinary(x) {
let bin = 0;
let rem, i = 1, step = 1;
while (x != 0) {
rem = x % 2;
console.log(
`Step ${step++}: ${x}/2, Remainder = ${rem}, Quotient = ${parseInt(x/2)}`
);
x = parseInt(x / 2);
bin = bin + rem * i;
i = i * 10;
}
console.log(`Binary: ${bin}`);
}
// take input
let number = prompt('Enter a decimal number: ');
convertToBinary(number);
Also in JavaScript:
- js add src to img
- javascript timestamp in seconds
- draw point p5js
- ionic g service services/auth ionic g service services/authGuard npm i @ionic/storage npm i @auth0/angular-jwt ionic cordova plugin add cordova-sqlite-storage
- escape in javascript
- javascript funtion
- multiple path names for a same component in react router
- the function tag in js
- loop through api response in react
- reverse array in javascript
- array fill
- convert string of expression in to expression in javascript
- hide checkbox jquery
- code to launch browser using javascript
- cre&atRefs react js
- stackable in amcharts 3
- platformer javascript
- set auto width sheetjs
- display none js
- js remove last character
- jstree search example
- python format json file
- laravel send http post request json
- how to change background image dynamically in react