LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

ascii to U16 array

Solved!
Go to solution

How can I convert an ascii string, into an array of U16

 

The string I have is:  0123400000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000

 

This needs to be casted into an array, and the array should read:

[0] 8961

[1] 64

[2] 0

[3] 0

[4] 0

[5] 0  etc

 

anyone have any ideas?

0 Kudos
Message 1 of 13
(4,210 Views)
How the 0123 has been converted to 8961 ?
0 Kudos
Message 2 of 13
(4,202 Views)
Plenty. Except that your information is incomplete. Where did you come up with 8961 from your string? It appears that you have little-endian, as 8961 = 2301 hex. Is this correct? Are those ASCII characters, or is that a string that is displayed in hex mode?
0 Kudos
Message 3 of 13
(4,200 Views)
Solution
Accepted by topic author morngoose

Now that I got work out of the way, back to this... Smiley Very Happy

 

Here's a quick and dirty solution (assuming that we have a string whose length is divisible by 4):

 

 

Message Edited by smercurio_fc on 01-28-2009 09:54 AM
Message 4 of 13
(4,185 Views)

This should work as well.

 

Message Edited by centerbolt on 01-28-2009 11:12 AM
0 Kudos
Message 5 of 13
(4,176 Views)
That won't work if the string consists of ASCII characters, as the poster initially seems to imply. It will work if the string being presented is in hex display mode.
0 Kudos
Message 6 of 13
(4,153 Views)

Smercurio_fc are correct Centerbolt. I have to admit I almost nominated Smercurio_fc solution as Rube Goldberg codeSmiley Very Happy. But I took a closer look at the problem.  I have also made my own solution in a more conservative fashion. But I think it will execute slower than Smercurio_fc suggestion

Message Edited by t06afre on 01-28-2009 07:06 PM


Besides which, my opinion is that Express VIs Carthage must be destroyed deleted
(Sorry no Labview "brag list" so far)
0 Kudos
Message 7 of 13
(4,139 Views)

t06afre wrote:

Smercurio_fc are correct Centerbolt. I have to admit I almost nominated Smercurio_fc solution as Rube Goldberg codeSmiley Very Happy.


I should have indicated that the solution I presented was based on the assumption that we were dealing with ASCII characters. Otherwise, it makes no sense, and I'd be the first one to nominate myself, believe me. 

 

If you're dying to nominate me to the Rube Goldberg thread I'm sure I can find some code for you that I've written in the past that would fit it in there. Smiley Very Happy

0 Kudos
Message 8 of 13
(4,128 Views)

Smercurio_fc is absolutely correct about my version.  It only works for a particular type of string.  I guess I made an assumption based on the types of data I typically get from my instruments.

 

One thing I've been trying to figure out is whether or not the input string would include characters A-F.  I pretty sure it will.  I'm not sure  Smercurio's example will work with the A-F characters.  The example posted by t06afre will handle the full range of hex characters.

0 Kudos
Message 9 of 13
(4,112 Views)

Good point! It will not.

 

Characters 0 through 9 are ASCII decimal 48-57, so they would work in that example.  But A through F are decimal 65 through 70.  A does not immediately follow 9 in the ASCII table.

0 Kudos
Message 10 of 13
(4,106 Views)