Created
July 12, 2018 07:45
-
-
Save ted-wq-x/a8cd5d1ad555686f7dfe9c523ea95606 to your computer and use it in GitHub Desktop.
26进制转换(A-Z:0-26;AA-AZ:27-52)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//----------------------26进制转换----------------------- | |
@Test | |
public void test14() { | |
String str = "QQ"; | |
char[] chars = str.toCharArray(); | |
int sum = 0,index=0; | |
for (int i = chars.length-1; i >=0 ; i--) { | |
sum += Math.pow(26, index++) * (chars[i] - 64) ; | |
} | |
System.out.println(sum); | |
} | |
/** | |
* a-z:97-122 | |
* A-Z:65-90 | |
*/ | |
@Test | |
public void convertToExcel(){ | |
int s = 459; | |
int i = s / 26; | |
StringBuilder stringBuilder = new StringBuilder(); | |
if (i != 0) { | |
stringBuilder.append((char) (i + 'A'-1)); | |
} | |
i = s % 26; | |
if (i == 0) { | |
stringBuilder.append('Z'); | |
} else { | |
stringBuilder.append((char) (i + 'A'-1)); | |
} | |
System.out.println(stringBuilder.toString()); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment