class Stack{
constructor() {
this.items = []
};
push(ele){
this.items.push(ele)
}
pop(){ //从栈顶删除
return this.items.pop()
}
peek(){ //返回栈顶元素
return this.items[this.items.length-1]
}
isEmpty(){
return this.items.length === 0
}
clear(){
this.items = []
}
size(){
return this.items.length
}
}
function decimalToBinary(decNumber){
const remStack = new Stack()
let number = decNumber
let binaryNumber = ""
while(number > 0){
let dec = Math.floor(number%2)
remStack.push(dec)
number = Math.floor(number/2)
}
while(!remStack.isEmpty()){
binaryNumber+=remStack.pop().toString()
}
// console.log(remStack)
return binaryNumber
}
console.log(decimalToBinary(233))
console