简体   繁体   English

在Java中如何将基数36转换为十进制数?

[英]In Java how do you convert a base 36 number to a decimal number?

给定基数为36的YPAYPA,是否有Java中的库函数将其转换为十进制数?

The below returns a String representation, in decimal, of the number. 下面返回数字的字符串表示形式(十进制)。

Long.valueOf("YPAYPA", 36).toString();

From the J2SE docs 来自J2SE文档

这甚至可以用于大数字。

new BigInteger("YPAYPA", 36).toString();

This sounds like a homework question. 这听起来像是一个家庭作业问题。 If it's not, then I apologize, but for now I will simply post some information that will help you find the right answer. 如果不是,那么我道歉,但现在我只是发布一些信息,帮助您找到正确的答案。

Since this is a base 36 number, I will assume that the values are [0-9][AZ], the values of the letters are A = 10, B = 11, etc. The easiest way of solving this is through powers. 由于这是一个基数36,我将假设值为[0-9] [AZ],字母的值为A = 10,B = 11等。解决这个问题的最简单方法是通过权力。 The position furthest to the right (A in your example) is 10 * (36 ^ 0), which would equal 10. P would be (15 * 36 ^ 1). 右边最远的位置(在你的例子中是A)是10 *(36 ^ 0),它等于10.P将是(15 * 36 ^ 1)。

Essentially it is the value of the digit, multiplied by the result of the base raised to the 0-based position it is in. Our decimal system works exactly the same way (10 ^ 0, 10 ^ 1, etc). 基本上它是数字的值,乘以基数提升到它所处的0基位置的结果。我们的十进制系统的工作方式完全相同(10 ^ 0,10 ^ 1等)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM