I want to convert any base to any base.
I’m using this right now:
void setup(){
println(baseConversion("JAVA",36,10));
}
String baseConversion(String input,int fromBase,int toBase){
return reverseCase(Integer.toString(Integer.parseInt(reverseCase(input),fromBase),toBase));
}
String reverseCase(String text){
char[] chars = text.toCharArray();
for(int i = 0; i < chars.length; i++){
char c = chars[i];
if(Character.isUpperCase(c)){
chars[i] = Character.toLowerCase(c);
}else if(Character.isLowerCase(c)){
chars[i] = Character.toUpperCase(c);
}
}
return new String(chars);
}
//"PROCESSING" is too large, so I use "JAVA".
It only works for radices under 32 now (obviously, the max radix of Java is 32), how can I get it to work for radices over 32, somewhat under 62?
Number list:
//0
//1
//2
//3
//4
//5
//6
//7
//8
//9
//A
//B
//C
//D
//E
//F
//G
//H
//I
//J
//K
//L
//M
//N
//O
//P
//Q
//R
//S
//T
//U
//V
//W
//X
//Y
//Z
//a
//b
//c
//d
//e
//f
//g
//h
//i
//j
//k
//l
//m
//n
//o
//p
//q
//r
//s
//t
//u
//v
//w
//x
//y
//z
//If you wants more
//`
//~
//!
//@
//#
//$
//%
//^
//&
//*
//(
//)
//-
//_
//=
//+
//[
//{
//]
//}
//\
//|
//etc.