exception - why Java throws a NumberFormatException -



exception - why Java throws a NumberFormatException -

i got exception while parsing string byte

string str ="9b7d2c34a366bf890c730641e6cecf6f"; string [] st=str.split("(?<=\\g.{2})"); byte[]bytes = new byte[st.length]; (int = 0; <st.length; i++) { bytes[i] = byte.parsebyte(st[i],16); }

that's because default parse method expects number in decimal format, parse hexadecimal number, utilize parse:

byte.parsebyte(st[i], 16);

where 16 base of operations parsing.

as comment, right. maximum value of byte 0x7f. can parse int , perform binary , operation 0xff lsb, byte:

bytes[i] = integer.parseint(st[i], 16) & 0xff;

java exception numberformatexception

Comments

Popular posts from this blog

iphone - Dismissing a UIAlertView -

c# - Can ProtoBuf-Net deserialize to a flat class? -

javascript - Change element in each JQuery tab to dynamically generated colors -