Js uses stacks to implement 10-to-8 conversion and divisor and remainder _ javascript tips-js tutorial

Source: Internet
Author: User
This article mainly introduces how js uses stacks to implement 10-to-8 conversion, while js uses divisor and remainder. For more information, see The Code is as follows:

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 p 8) * 8 + (N mod 8) (p indicates the division operation, and mod indicates the division operation)

For an input non-negative decimal integer to octal, the calculation process is to generate all digits of the octal sequence from low to high. During output, the values should generally be from high to low, this is the opposite of the computing process.

Note: The integer parseInt must be used to obtain the divisor.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.