01-28-2009 09:03 AM
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?
Solved! Go to Solution.
01-28-2009 09:15 AM
01-28-2009 09:16 AM
01-28-2009 09:53 AM - edited 01-28-2009 09:54 AM
Now that I got work out of the way, back to this...
Here's a quick and dirty solution (assuming that we have a string whose length is divisible by 4):
01-28-2009 10:10 AM - edited 01-28-2009 10:12 AM
This should work as well.
01-28-2009 10:58 AM
01-28-2009 12:04 PM - edited 01-28-2009 12:06 PM
Smercurio_fc are correct Centerbolt. I have to admit I almost nominated Smercurio_fc solution as Rube Goldberg code. 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
01-28-2009 12:48 PM
t06afre wrote:Smercurio_fc are correct Centerbolt. I have to admit I almost nominated Smercurio_fc solution as Rube Goldberg code.
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.
01-28-2009 02:35 PM
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.
01-28-2009 02:52 PM
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.