binary to int javascript
var digit = parseInt(binary, 2);let binary = 0001
parseInt(binary, 2)
// returns 1const binaryArrayToNumber = arr => {
let len = arr.length
let pow = []
let decimal = []
for(let i = 0; i <= len - 1; i++){
pow.unshift(i)
}
arr.forEach((x,index) => {
decimal.push(x*2**pow[index])
})
let toDecimal = decimal.reduce((acc, curr) => acc + curr, 0)
return toDecimal
};
console.log(binaryArrayToNumber([1, 0, 1, 1]))
Also in JavaScript:
- get top items from json object
- ionic modal navbar not showing
- inverser l'ordre des item d'un array js
- switch case in js
- define a while loop in node js
- react Refused to execute inline script because it violates the following Content Security Policy directive
- know if a mobile open the website js
- require("history").createBrowserHistory` instead of `require("history/createBrowserHistory")`
- jquery ajax upload image
- javascript sort by id
- jquery li count in ul
- javascript change page title
- using multiparty with node js express
- js jquery class ending with string
- google script define array
- how to load localt ext file in js
- input output ionic
- access json python
- vue.js use scss in balise style
- js add item to array
- How to copy text from a div to clipboard
- js set visibility
- js detect mobile
- generate an array of random numbers javascript