当前位置:网站首页>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;
});
};
边栏推荐
- Jianzhi offer II 062. implement prefix tree (medium design dictionary tree prefix tree string)
- Alibaba cloud CDN practice
- Sword finger offer II 056. Sum of two nodes in a binary search tree (simple binary search tree DFS hash table double pointer iterator)
- Principle of object. Prototype. ToString. Call()
- [CS231N]Lecture_2:Image Classification pipelin
- HCIP(8)
- hcip实验(14)
- [Ruiji takeout] day05 package management business development
- 96. Different binary search trees (medium binary search tree dynamic planning)
- HCIP(15)
猜你喜欢
阿里云CDN实践
内网渗透学习(三)域横向移动——计划任务
Intranet penetration learning (III) horizontal movement of domain - planning tasks
Record the fluent to solve the problem of a renderflex overflowed by 7.3 pixels on the bottom
98. Verify binary search tree (medium binary search tree DFS)
[Ruiji takeout project] Day5 - Chapter 6 mobile verification code login
HCIP(13)
想要快速成长,先要经历重大打击!
Ruiji takeout project - development of business development function Day2
Hcip experiment (12)
随机推荐
From Web3 to web2.5, is it backward or another way?
Establishment of Ruiji takeout development environment
HCIP(10)
Lin Xiaobin, head of Tencent cloud database, borrowed 100 million yuan to speculate in stocks? Insider: the amount is not true
The binary search boundary value processing based on leetcode35 is used to clarify the boundary value of the judgment condition using the idea of interval
What testing services do third-party software testing institutions provide? Charging standard of software test report
[LiteratureReview]Object Detection and Mapping with Bounding Box Constraints
Which is the file transfer command in the basic services of the Internet
LVS+KeepAlived高可用部署实战应用
ssh 免密码登录
Win11怎么打开软件通知
Static details of static members
【CVPR 2021】Cylinder3D:用于LiDAR点云分割的圆柱体非对称3D卷积网络
Basic introduction of Rockwell AB PLC rslogix digital quantity IO module
Necessary for in-depth learning: split the data set, split the labels according to the split pictures, and check the interval of all marked labels
lotus 1.16.0 延长扇区过期时间
XXX port is already in use
静态成员static详解
HCIP(11)
HCIP(11)