61
Botdev / Re: [JAVA, W3XP, W3GS] Host Counter Decoding
« on: December 07, 2009, 04:03:52 pm »Are you supposed to drop half of the digits, or are you concatenating two digits together, and then converting the pairs to 4 bytes? I know what the character array looks like as a string, but that doesn't help much.
Maybe since this is the bot dev thread, there's some context I'm missing out on, but it seems that you left essential details out of the problem specification. It seems like an easy task whatever it is you're trying to do, but it's hard to answer a question when there's something missing.
Incidentally, your code only indexes 0 - 4 of the original array. You want to index 2*i and 2*i+1, not i and i+1, unless you're meaning to throw out some of the digits.
I am trying concatenate four pairs of two digits into bytes. In the string, two characters are meant represent one byte so I am not losing any of the digits!
Unfortunately, the code above does not work:
Code: [Select]
java.lang.NumberFormatException: For input string: ""
at java.lang.NumberFormatException.forInputString(NumberFormatException.java:65)
EDIT:
Got it working!
Code: [Select]
byte[] processedHostCounter = new byte[4];
for(int i = 0; i < 4; i++) {
processedHostCounter[i] = (byte)Integer.parseInt(new String(new byte[] { hostCounter[i + 1], hostCounter[i] }));
}
Thanks everyone