Skip to content

Instantly share code, notes, and snippets.

@ted-wq-x
Created July 12, 2018 07:45
Show Gist options
  • Save ted-wq-x/a8cd5d1ad555686f7dfe9c523ea95606 to your computer and use it in GitHub Desktop.
Save ted-wq-x/a8cd5d1ad555686f7dfe9c523ea95606 to your computer and use it in GitHub Desktop.
26进制转换(A-Z:0-26;AA-AZ:27-52)
//----------------------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