02-10-2010 02:49 AM
Hello,
I want to convert a string with hex number to byte array, this string includes a tip information, but I don't want to add this tip to byte arry.
the detail information please see the picture. I hope someone can give me some instructions, thanks a lot.
Solved! Go to Solution.
02-10-2010 02:56 AM
You could do something like this (if you always have 4 bytes)
The constant wired to the default value is U8 representation.
Hope this helps.
02-10-2010 02:59 AM
You could provide more information, like do all of the tips start with a ' symbol?
Also you could add some example code.
Am I going to the right direction?
02-10-2010 03:00 AM
Hello Dan,
The number of bytes is not a constant. It depends on the message command. So I should filter the tip information.
02-10-2010 03:12 AM
Then you can read until it can't scan a hex code anymore.
See image.
To be on the safe side, you could also cut the string like suggested by Giedrius.
I don't think the solution from Giedrius will result in what you want since it will convert every single byte into its ASCII code. FF for instance will result in an array of x70,x70 instead of xFF.
02-10-2010 10:04 AM - edited 02-10-2010 10:04 AM
The accepted solution provided by Giedrius.S is not correct, based on the picture shown in the first post. That solution will not eliminate the spaces before the tip, and the string to byte array will convert the individual characters of "0", "8", "space", "9", etc. to they byte values. The correct solution, based on the picture is shown below:
02-10-2010 10:13 AM
smercurio_fc wrote:That solution will not eliminate the spaces before the tip, and the string to byte array will convert the individual characters of "0", "8", "space", "9", etc. to they byte values.
Must agree on both of these. I haven't processed the spaces and missed the formatting necessary before the converson to binary. The author should remark the solution.
02-10-2010 07:32 PM
Hello Smercurio_fc,
your solution is absolutely correct , thanks a again.
Meanwhile, thanks to Dan and Giedrius.S, your solution gives me some ideas.
WGQ