64進数

備忘録:Java 64進数
自動で生成する方法がわからず、手打ちヽ(`Д´)ノ
悔しいので貼る。

public int s64toNum(String targetNum){
int rValue = -1;
if(targetNum.equals("0")){
rValue =0;
}else if(targetNum.equals("1")){
rValue =1;
}else if(targetNum.equals("2")){
rValue =2;
}else if(targetNum.equals("3")){
rValue =3;
}else if(targetNum.equals("4")){
rValue =4;
}else if(targetNum.equals("5")){
rValue =5;
}else if(targetNum.equals("6")){
rValue =6;
}else if(targetNum.equals("7")){
rValue =7;
}else if(targetNum.equals("8")){
rValue =8;
}else if(targetNum.equals("9")){
rValue =9;
}else if(targetNum.equals("a")){
rValue =10;
}else if(targetNum.equals("b")){
rValue =11;
}else if(targetNum.equals("c")){
rValue =12;
}else if(targetNum.equals("d")){
rValue =13;
}else if(targetNum.equals("e")){
rValue =14;
}else if(targetNum.equals("f")){
rValue =15;
}else if(targetNum.equals("g")){
rValue =16;
}else if(targetNum.equals("h")){
rValue =17;
}else if(targetNum.equals("i")){
rValue =18;
}else if(targetNum.equals("j")){
rValue =19;
}else if(targetNum.equals("k")){
rValue =20;
}else if(targetNum.equals("l")){
rValue =21;
}else if(targetNum.equals("m")){
rValue =22;
}else if(targetNum.equals("n")){
rValue =23;
}else if(targetNum.equals("o")){
rValue =24;
}else if(targetNum.equals("p")){
rValue =25;
}else if(targetNum.equals("q")){
rValue =26;
}else if(targetNum.equals("r")){
rValue =27;
}else if(targetNum.equals("s")){
rValue =28;
}else if(targetNum.equals("t")){
rValue =29;
}else if(targetNum.equals("u")){
rValue =30;
}else if(targetNum.equals("v")){
rValue =31;
}else if(targetNum.equals("w")){
rValue =32;
}else if(targetNum.equals("x")){
rValue =33;
}else if(targetNum.equals("y")){
rValue =34;
}else if(targetNum.equals("z")){
rValue =35;
}else if(targetNum.equals("A")){
rValue =36;
}else if(targetNum.equals("B")){
rValue =37;
}else if(targetNum.equals("C")){
rValue =38;
}else if(targetNum.equals("D")){
rValue =39;
}else if(targetNum.equals("E")){
rValue =40;
}else if(targetNum.equals("F")){
rValue =41;
}else if(targetNum.equals("G")){
rValue =42;
}else if(targetNum.equals("H")){
rValue =43;
}else if(targetNum.equals("I")){
rValue =44;
}else if(targetNum.equals("J")){
rValue =45;
}else if(targetNum.equals("K")){
rValue =46;
}else if(targetNum.equals("L")){
rValue =47;
}else if(targetNum.equals("M")){
rValue =48;
}else if(targetNum.equals("N")){
rValue =49;
}else if(targetNum.equals("O")){
rValue =50;
}else if(targetNum.equals("P")){
rValue =51;
}else if(targetNum.equals("Q")){
rValue =52;
}else if(targetNum.equals("R")){
rValue =53;
}else if(targetNum.equals("S")){
rValue =54;
}else if(targetNum.equals("T")){
rValue =55;
}else if(targetNum.equals("U")){
rValue =56;
}else if(targetNum.equals("V")){
rValue =57;
}else if(targetNum.equals("W")){
rValue =58;
}else if(targetNum.equals("X")){
rValue =59;
}else if(targetNum.equals("Y")){
rValue =60;
}else if(targetNum.equals("Z")){
rValue =61;
}else if(targetNum.equals("#")){
rValue =62;
}else if(targetNum.equals("$")){
rValue =63;
}else{
rValue =0;
}
return rValue;
}
//数値型から64進数文字列への変換
public String numToS64(int num){
switch(num){
case 0:
return "0";
case 1:
return "1";
case 2:
return "2";
case 3:
return "3";
case 4:
return "4";
case 5:
return "5";
case 6:
return "6";
case 7:
return "7";
case 8:
return "8";
case 9:
return "9";
case 10:
return "a";
case 11:
return "b";
case 12:
return "c";
case 13:
return "d";
case 14:
return "e";
case 15:
return "f";
case 16:
return "g";
case 17:
return "h";
case 18:
return "i";
case 19:
return "j";
case 20:
return "k";
case 21:
return "l";
case 22:
return "m";
case 23:
return "n";
case 24:
return "o";
case 25:
return "p";
case 26:
return "q";
case 27:
return "r";
case 28:
return "s";
case 29:
return "t";
case 30:
return "u";
case 31:
return "v";
case 32:
return "w";
case 33:
return "x";
case 34:
return "y";
case 35:
return "z";
case 36:
return "A";
case 37:
return "B";
case 38:
return "C";
case 39:
return "D";
case 40:
return "E";
case 41:
return "F";
case 42:
return "G";
case 43:
return "H";
case 44:
return "I";
case 45:
return "J";
case 46:
return "K";
case 47:
return "L";
case 48:
return "M";
case 49:
return "N";
case 50:
return "O";
case 51:
return "P";
case 52:
return "Q";
case 53:
return "R";
case 54:
return "S";
case 55:
return "T";
case 56:
return "U";
case 57:
return "V";
case 58:
return "W";
case 59:
return "X";
case 60:
return "Y";
case 61:
return "Z";
case 62:
return "#";
case 63:
return "$";
default:
return "0";
}
}

みんな64進数の最後の二文字って何使ってるんだろ(´・ω・`)?

※090605追記 このエントリのトラックバック先にもっとスマートなコードが掲載されていたのだけれど、何故か消されてしまってる。勝手に転載してしまうのもまずいのでかいつまんで書いておくと、Stringに0-9+a-z+A-z+2文字を格納しておいて、それをindexOfで数字を、substringで文字を引っ張ってくるという形だったような…。

※110126追記
※131031追記
64進数変換にサンプルを載せました。