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