1、十进制转化二进制
<script>
var num = 10;
var arr = [];
while(num>0){
arr.unshift(num%2);
num = Math.floor(num/2);
}
console.log(Number(arr.join("")))
</script>
2、二进制转十进制
<script>
var num = 1010;
str = (num+"").split("").reverse();
console.log(str);
var sum = 0;
str.forEach((item,index)=>{
console.log(item);
console.log(index);
sum+=item*Math.pow(2,index);
})
console.log(sum)
</script>