Archive: converting bytes into string, string into int, then back.


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


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)?


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


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.


so

StrCpy $0 "1234"
IntOp $1 $0 + 16432
StrCmp $1 "input" match nomatch

is not what you want?