I've been staring at this for hours, trying this and that, and still don't see what's wrong. I know that it's ok to:
But in the context of this code, I get a NumberFormatException. As you can see, I've been looking at the character array and String and don't see any problem with it. When I simplify (beyond what is possible in the actual application) by just setting a string value to the number that I get from the algorithm, all is fine. When I create a char array and set it, all is fine. Just can't see why this is throwing the exception.
I fixed the posted problem by using long instead of int. But I'm concerned (and don't know a big-endian from a little indian). The test process came from a real example. From the spec:
For each of these fields, the server has to take the digits from the
value to obtain a number (in this case 1868545188 and 1733470270
respectively), then divide that number by the number of spaces
characters in the value (in this case 12 and 10) to obtain a 32-bit
number (155712099 and 173347027). ,,,,,
The concatenation of the number obtained from processing the |Key1| field,
expressed as a big-endian 32-bit number, the
number obtained from processing the |Key2| field, again
expressed as a big-endian 32-bit number, and finally the eight bytes
at the end of the handshake, form a 128 bit string .....
Roger F. Gay
Joined: Feb 16, 2007
Never mind, I guess. After dividing by the number of spaces, the result is 32-bit. No problem there. I just panicked because I don't really understand what a big-endian is and whether I have to do anything special.
Joined: Apr 30, 2005
Roger F. Gay wrote:Never mind, I guess. After dividing by the number of spaces, the result is 32-bit. No problem there. I just panicked because I don't really understand what a big-endian is and whether I have to do anything special.
Big endian logic stores the most significant byte (MSB) first. An int number is 32bit which means it takes 4 bytes in memory, so the number 123456789 (75BCD15 in hex) would be stored as  [5B] [CD]  where little-endian would store it as  [CD] [5B]