numberformatexception - number format exeption in java -
numberformatexception - number format exeption in java -
hello i`m working on project , had convert hex string binary string used lot of methods code below useful me although code creates unknown hex number "l" looks 1 not one, 1 know thing is(l)? , how did appear , how prepare , convert "1" ?
public string hextobin(string hex){ string bin =new string(); string binfragment =new string(); int ihex; hex = hex.trim(); hex = hex.replacefirst("0x",""); for(int = 0; < hex.length(); i++){ ihex = integer.parseint(""+hex.charat(i),16); binfragment = integer.tobinarystring(ihex); while(binfragment.length() < 4){ binfragment = "0" + binfragment; } bin += binfragment; }
you should utilize integer.decode()
instead of integer.parseint()
handles hex strings well. see; http://docs.oracle.com/javase/7/docs/api/java/lang/integer.html#decode(java.lang.string)
java numberformatexception
Comments
Post a Comment