Old 11th September 2007, 15:58   #1
brad harper
Junior Member
 
Join Date: May 2007
Posts: 2
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
brad harper is offline   Reply With Quote
Old 11th September 2007, 16:51   #2
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
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)?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th September 2007, 16:54   #3
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
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

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Old 11th September 2007, 19:11   #4
brad harper
Junior Member
 
Join Date: May 2007
Posts: 2
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.
brad harper is offline   Reply With Quote
Old 11th September 2007, 19:46   #5
Anders
Moderator
 
Anders's Avatar
 
Join Date: Jun 2002
Location: ${NSISDIR}
Posts: 5,449
so

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

is not what you want?

IntOp $PostCount $PostCount + 1
Anders is offline   Reply With Quote
Reply
Go Back   Winamp & Shoutcast Forums > Developer Center > NSIS Discussion

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump