Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

Java Programming Issue

  • 31-05-2005 01: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, Registered Users 2 Posts: 6,655 ✭✭✭daymobrew


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


  • Registered Users, Registered Users 2, Paid Member Posts: 2,427 ✭✭✭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