2013年9月17日星期二

hexadecimal string in java problem

turn int Many people say that the Internet so you can turn ah , but how do I use on an exception , as follows:
int iValue = Integer.parseInt ("0x30", 16); / / This will generate an exception
int iValue = Integer.parseInt ("30", 16); / / That's right , the result is 48.
really do not understand why . . . A friend can talk about what
------ Solution ---------------------------------- ----------
0x in front can be removed
------ Solution -------------------- ------------------------
intercept what can not it
int iValue = Integer.parseInt ("0x30". subString (2, "0x30". length), 16);
------ Solution - -------------------------------------------
int iValue = Integer.parseInt("0x30".replace("0x",""), 16);
< br> ------ For reference only ---------------------------------------

I want to be able to directly read , because all the text beginning with 0x . What can be achieved ?
------ For reference only -------------------------------------- -

I want to be able to directly read , because all the text beginning with 0x . What can be achieved ?  

then use string interception way it

没有评论:

发表评论