Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

十进制转二十六进制 #75

Open
Liqiuyue9597 opened this issue Dec 10, 2020 · 0 comments
Open

十进制转二十六进制 #75

Liqiuyue9597 opened this issue Dec 10, 2020 · 0 comments

Comments

@Liqiuyue9597
Copy link
Owner

设定如下的对应关系(A=1,B=2,C=3,...,Z=26,AA=27,AB=28,....AZ=, BA=, .....AAA=, ...),编写一个转换函数,根据上面的规则把一个字符串: "WECHAT" 转换为数字。
其实没有很好的计算机基础知识很难发现这是一道进制转换的题,如果发现不了这道题就没法解。
利用进制转换的公式:

function rule(s) {
  let sum = 0;
  for (let i = s.length - 1; i >=0; i--) {
    sum += (s.charCodeAt(i) - 65 + 1) * Math.pow(26, s.length - i - 1);
  }
  return sum;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant