How to convert an integer to a string in base b with Java

1 Answer

0 votes
public class IntegerToStringBase {
    public static void main(String[] args) {
        int number = 255; // Example integer
        int base = 16;    // Example base (hexadecimal)

        // Convert integer to string in the specified base
        String result = Integer.toString(number, base).toUpperCase();

        System.out.println("Number in base " + base + ": " + result);
    }
}



/*
run:

Number in base 16: FF

*/

 



answered Aug 17, 2025 by avibootz
...