brad harper
11th September 2007 16:58 UTC
converting bytes into string, string into int, then back.
Hello All:
I may have missed this issue in old posts or the FAQ, but bear with me. I'm attempting to emulate the following Java behavior in an NSIS installer:
byte[] password = new byte[4];
...
String str = new String(password, 0, 4);
int i = Integer.parseInt(str);
i += 16432;
String image = String.valueOf(i);
int b = image.compareTo(inputString);
The crux is the conversion of four sequential bytes (representing ASCII character codes) into the equivalent string, parsing this string value into an int, and then converting the int back into its string image.
Has anyone seen anything similar to this?
Cheers.
Brad
Anders
11th September 2007 17:51 UTC
http://nsis.sourceforge.net/Asc
and
IntFmt $0 "%c" 65
should get you started, or should Integer.parseInt() give you a int from 4 bytes (4 char's)?
Anders
11th September 2007 17:54 UTC
or is this an actual string that is always formated like a number, eg "136532"? In NSIS there are no int's, everything is stored as a string, for things like IntCmp and IntOp, the string is converted to a number, operation takes place and result is stored as a string in the output variable
brad harper
11th September 2007 20:11 UTC
The parseInt() method call is like the atoi() function in C.
The four bytes are interpreted as a string, which is itself interpreted as the image of an integer value.
Anders
11th September 2007 20:46 UTC
so
StrCpy $0 "1234"
IntOp $1 $0 + 16432
StrCmp $1 "input" match nomatch
is not what you want?