05-25-2011 02:31 AM
Hello,
Sorry for typing on same topic, but I still do not understant what will happen when I type cast 2-bytes string into U16. Could you please explain me this?
Regards,
__behemot_
Solved! Go to Solution.
05-25-2011 07:09 AM
You will get the ASCII code of the first character as the high byte and the ASCII code of the second character as the low byte.
Or, in other words, the U16 value will be 256*asc(ch1)+asc(ch2). asc() is the ASCII code of a character.
05-26-2011 02:43 AM
Hi,
All of ASCII character are represented in 8 bits in the memory. If you imagine these 8 bits, you can concatenate them. That will be the 16 bit long integer (in this case, when you have a 2 elements string), and obviously unsigned, because there is no sign defined in ASCII values.
So, both of integer and character are represented in the same way in the memory, but LabVIEW knows that which type is stored in which variable. If you want to operating with ASCII characters as you would have numbers, you should cast it to integer then you can multiply it and etc. For instance, if you want to change 'a' to 'A', you can cast it to U8 integer than you should substract 20 from it and cast it back to character (1 element string).
I hope it will help you to understand type casting. If you have further questions, please write again.
Regards,
Peter
05-26-2011 04:25 AM
@PeterV_hun wrote:
... if you want to change 'a' to 'A', you can cast it to U8 integer than you should substract 20 from it and cast it back to character (1 element string).
That would be 20 in hex representation (or 32 in decimal).
05-26-2011 04:38 AM
Right, thanks 🙂
Peter
05-26-2011 08:48 AM
Thank you very much for all responses. It was very usefull. 🙂
11-03-2011 11:14 AM
Hi everyone.
I've a question about the given answer.
How to adapt it to convert string of 4 characters in a u16 word?
In fact, i read from a csv file, value like 0x0001, 0xFFEB etc. I know how to cut '0x' but no to cast from string to U16.
I need to do this, because, i need to use subvi who takes U16 value on inputs.
Thanks
11-03-2011 12:05 PM
No Type Cast required here (darn), simply use Hexadecimal String to Number (clip the 0x), or skip the middle man and use Spreadsheet String To Array to go directly from CSV data to the U16 Array.