Conversion Between the 10th and 62th in javascript, javascript62

Source: Internet
Author: User

Conversion Between the 10th and 62th in javascript, javascript62

function string10to62(number) {  var chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ'.split(''),    radix = chars.length,    qutient = +number,    arr = [];  do {    mod = qutient % radix;    qutient = (qutient - mod) / radix;    arr.unshift(chars[mod]);  } while (qutient);  return arr.join('');}function string62to10(number_code) {  var chars = '0123456789abcdefghigklmnopqrstuvwxyzABCDEFGHIGKLMNOPQRSTUVWXYZ',    radix = chars.length,    number_code = String(number_code),    len = number_code.length,    i = 0,    origin_number = 0;  while (i < len) {    origin_number += Math.pow(radix, i++) * chars.indexOf(number_code.charAt(len - i) || 0);  }  return origin_number;}

Convert decimal number 62 to binary number Yes

(62) 10
= (0*1010 + 110) * 1010 + 10) 2
= (110*1010 + 10) 2
= (111100 + 10) 2
= (0, 111110) 2

Javascript 10-to-16-to-zero

Because js does not have a method similar to '0' * x, and there is no function similar to using a character string that is less than the specified length, you can only write
Function str_pad (hex ){
Var zero = '20140901 ';
Var tmp = 8-hex.length;
Return zero. substr (0, tmp) + hex;
}

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.