Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

Java Programming Issue

Options
  • 31-05-2005 1:43pm
    #1
    Closed Accounts Posts: 390 ✭✭


    I have a string of hex values, e.g. "6A 13 20 CB 20 31"

    I parse the string using a StringTokenizer to get the individual hex values:
    6A
    13
    20
    CB
    etc.

    I then iterate over the hex values converting each one to a byte and adding it to a byte array. I use Byte.parseByte method to convert the string hex value to the byte value. However every time I get to the CB value an exception is thrown as follows:
    java.lang.NumberFormatException: Value out of range. Value:"CB" Radix:16
    at java.lang.Byte.parseByte(Byte.java:124)
    at com.openjawx.opodo.utils.DecodeProcess.loadFromRuleStr(DecodeProcess.java:306)
    at com.openjawx.opodo.utils.DecodeProcess.getKEK(DecodeProcess.java:94)
    at com.openjawx.opodo.utils.DecodeProcess.doDecode(DecodeProcess.java:108)
    at com.openjawx.opodo.utils.DecodeProcess.main(DecodeProcess.java:60)

    Any ideas as to how I can get around this issue?

    Thanks
    roar_ie


Comments

  • Registered Users Posts: 6,508 ✭✭✭daymobrew


    The problem is that the range of Byte is -80 to 7F.
    See a thread about it on Google Groups.


  • Registered Users Posts: 2,426 ✭✭✭ressem


    You are using
    Byte.ParseByte(x,16)?

    You can't just use an array of ints/shorts to store results?

    ParseByte is a wrapper around ParseInt with a built in boundary check, that means you can't use it unless you are sure that no bytes are above 7F.

    There's a check in the Java code that throws this exception if
    i=Integer.ParseInt(x,16) returns a result < -128 or > 127.


  • Closed Accounts Posts: 390 ✭✭roar_ie


    Cheers, that was spot on.

    roar_ie


Advertisement