If you want to parse base-10 to base-n String
you can use something like :
System.out.println(Integer.toString(3, 2)); // print 11 -> String data type
Code above is to parse 3
in base 10 (integer) as binary (base-2) String
.
Following code should parse base-2 String
as base-10 integer value :
System.out.println(Integer.parseInt("11", 2)); // print 3 -> base-10 integer
Code above is to parse 11
binary to base-10 integer. Your code have error with this String format, for base-3 the string only consist 0
, 1
, 2
.
Please note the difference how to use both method.