Radix 32+ Converter

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.

Interesting question!
Are you familiar with how characters are represented on the byte level? If not, look into ASCII encoding and “character algebra”
Why have that “reverse case” function?

1 Like

(My apology for the late reply. Different timeline, I suppose)

Yes, I’m familiar with ASCII and Unicode

Searching “character algebra” return me “character theory”

The reverseCase is to reverse the output letters (Java radix output lowercase letters).

I think you have all the tools, but I can’t help you anymore until you further clarify your problem.

This is just the start of the question. From here you have to start breaking it down. What information does someone else need to know to start helping you. What have you already tried. Wheres the code that is giving you problems?

1 Like

Never mind, my brain is fooling myself…
I was trying to find a converter for floating point when I am not needing it at all

1 Like