且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

在数字基之间转换数字

更新时间:2023-11-26 08:22:58

您需要为每个字母分配一个数字",例如:

You need to assign a "digit" to each letter, like:

A =  0     N = 13
B =  1     O = 14
C =  2     P = 15
D =  3     Q = 16
E =  4     R = 17
F =  5     S = 18
G =  6     T = 19
H =  7     U = 20
I =  8     V = 21
J =  9     W = 22
K = 10     X = 23
L = 11     Y = 24
M = 12     Z = 25

然后,您的{20,13}变为UN.

转换为UN -> {20,13} -> (20 * 26 + 13) -> 52.

通过进一步的示例,让我们尝试10163,它是随机抽取的.

By way of further example, let's try the number 10163, just plucked out of the air at random.

将其除以26,直到得到小于26的数字(即两次),然后得到 15 ,其分数为0.03402366.

Divide that by 26 until you get a number less than 26 (i.e., twice), and you get 15 with a fractional part of 0.03402366.

将其乘以26,您将得到 0 ,分数为0.88461516.

Multiply that by 26 and you get 0 with a fractional part of 0.88461516.

那个乘以26,您会得到 23 (实际上在我的计算器上为22.99999416,但是由于初始除法只有两步,所以我们在这里停止-略有误差是由于对浮点数进行了四舍五入).

Multiply that by 26 and you get 23 (actually 22.99999416 on my calculator but, since the initial division was only two steps, we stop here - the very slight inaccuracy is due to the fact that the floating point numbers are being rounded).

因此,数字"是{15,0,23},这是数字" PAX.哇,真是巧合?

So the "digits" are {15,0,23} which is the "number" PAX. Wow, what a coincidence?

要将PAX转换回十进制,其

  P * 262 + A * 261 + X * 260

 P * 262 + A * 261 + X * 260

  (15 * 676) + (0 * 26) + 23
= 10140      + 0        + 23
= 10163