java - Failed to parse int 3 in base 3 -
strangest thing. have line
int = integer.parseint("3",3);
but everytime run it, numberformatexception.forinputstring. why? simple base conversion. special int 3 breaks conversion?
if want parse base-10 base-n string
can use :
system.out.println(integer.tostring(3, 2)); // print 11 -> string data type
code above parse 3
in base 10 (integer) binary (base-2) string
.
following code should parse base-2 string
base-10 integer value :
system.out.println(integer.parseint("11", 2)); // print 3 -> base-10 integer
code above parse 11
binary base-10 integer. code have error string format, base-3 string consist 0
, 1
, 2
.
please note difference how use both method.
Comments
Post a Comment