Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function toDecimal(a){
- let binary= '';
- if (typeof a == 'string'){
- binary = a.split();
- } else {
- binary = a.toString().split();
- }
- let decimal = 0;
- for (let i=0; i < binary.length; i++){
- decimal = (decimal*2)+ binary[i];
- }
- return decimal;
- }
- console.log(toDecimal(00001001));
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement