Js USES the stack to implement decimal to decimal and take divisor and remainder

  • 2020-03-30 03:18:55
  • OfStack

 
function ten2eight(x){ 
var s=[]; 
var r=''; 
while(x>0){ 
s.push(x%8); 
x=parseInt(x/8); 
} 
while(s.length>0){ 
r=r+s.pop(); 
} 
return r; 
} 

N=(N div 8)*8+(N mod 8) (div is divisible, mod is mod)

For the input of a non-negative decimal integer converted to octal, the calculation process from the low to the high order to produce octal digits, and the output, generally from the high to low, and the reverse of the calculation process.

Note: when you take a divisor, you need to round parseInt

Related articles: