当前位置:网站首页>JS convert numbers to letters
JS convert numbers to letters
2022-07-28 22:28:00 【A little square】
Numbers into letters
a=>1;b=>2;.aa=>27 wait
The essence of the problem is Hexadecimal conversion , The principle of binary conversion is
aaaa = 1×26^3 + 1×26^2 + 1×26^1 + 1×26^0 = 18279
abcd = 1×26^3 + 2×26^2 + 3×26^1 + 4×26^0 = 19010
This leads to a formula for converting letters into numbers . First, get the length of the letter string n, Then a single string is converted into a number (1-26).
Such as abcdef, You know n=6, transformation :
1. a×26^(n-1) + b×26^(n-2) + c×26^(n-3) + d×26^(n-4) + e×26^(n-5) + f×26^(n-6)
2. 1×26^(5) + 2×26^(4) + 3×26^(3) + 4×26^(2) + 5×26^(1) + 6×26^(0)
According to this, we can deduce the calculation process of converting numbers into letters ( adopt Remainder To achieve , Note the remainder m by 0 Reset it to 26, because 0 The corresponding letter is z), Give any greater than 0 The natural number of x Yes :
const number_to_word = (x) => {
let s = "";
while (x > 0) {
let m = x % 26;
m = m === 0 ? (m = 26) : m;
s = String.fromCharCode(96 + parseInt(m)) + s;
x = (x - m) / 26;
}
return s;
});
};
边栏推荐
- Aimbetter insight into your database, DPM and APM solutions
- 静态成员static详解
- Learning notes and summary of C language programming specification
- Summary of the use of hash table set and map when leetcode brushes questions
- mysql8.0无法给用户授权或提示You are not allowed to create a user with GRANT的问题
- Use webworker to perform background tasks
- TensorFlow Serving 高性能的机器学习模型服务系统
- [LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
- [Ruiji takeout project]day4 - dish management
- CDN working principle
猜你喜欢

Static route and default route experiment

Overall introduction of Ruiji takeout project

79. Word search (medium string array matrix backtracking)

SQL injection less42 (post stack injection)

Day3 classification management of Ruiji takeout project

hcip实验(15)

Can the MySQL create statement be used to create a table structure and append new records

Hcip experiment (12)

Desai wisdom number - line chart (stacking area chart): ranking of deposits of different occupational groups in the proportion of monthly income in 2022

示波器发展史中的变化
随机推荐
Clearing of applet component timer
【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
Aimbetter insight into your database, DPM and APM solutions
什么是时间复杂度
Jmeter 安装第三方插件 Plugins Manager
Openresty request authentication
What are the main functions and uses of LCR tester
Learning notes and summary of C language programming specification
静态成员static详解
2021数学建模B组练习
Soft exam network engineer
Ukrainian officials: half of Ukrainian agricultural products are exported through the Danube port
Netease Yunxin 2022q2 product supply station, come and get your product supply plan!
HCIP(12)
Brief introduction to PCB materials
HCIP(13)
Excel-VBA 快速上手(十三、日期的常见用法)
96. Different binary search trees (medium binary search tree dynamic planning)
SQL注入 Less38(堆叠注入)
[leetcode] maximum depth of binary tree