LabVIEW

cancel
Showing results for 
Search instead for 
Did you mean: 

cast ascii to decimal

hi

 

im having a slight issue converting ascii to decimal.

 

i have an ascii string which is basically an incrementing number.

when i look at it as a hex string (by setting hex code in an indicator) i get:

0001

0002

0003

 

and so on.

however, when i convert this ascii string to decimal i get really large numbers.

when i get 0002 the decimal number is 131072.

this is equivalent to 20000 hex.

 

so it appears that i have 4 trailing hex zeros in there. not sure where they come from or how to get rid of them.

 

any ideas anyone?

0 Kudos
Message 1 of 6
(2,937 Views)
You convert to I32 instead of U16 is my guess. 🙂
/Y
G# - Award winning reference based OOP for LV, for free! - Qestit VIPM GitHub

Qestit Systems
Certified-LabVIEW-Developer
Message 2 of 6
(2,934 Views)

brilliant thanks

 

working

0 Kudos
Message 3 of 6
(2,932 Views)

@slugger wrote:

im having a slight issue converting ascii to decimal.


Next time also try to be more specific. 😄

  • The words "cast" and "convert" mean very different things, so don't use them interchangeably. (detals)
  • Your input is NOT ASCII (a character encoding scheme) but just a plain string.
  • The word "decimal" is a formatting specification, not a numeric data type.

Your problem also shows why type cast is relatively dangerous unless you know exactly what you are doing. There is no error output, e.g. if the string is shorter than needed for the datatype. It would be safer to use "unflatten from string" becaue it would alert you about the data mismatch at run time.

0 Kudos
Message 4 of 6
(2,890 Views)

That was throwing me off too, especially considering 0x30-0x39 are the ASCII values for 0-9.  0x01-0x09 result in characters that can't be seen.  I wouldn't expect them to show up as recognizable numbers.

0 Kudos
Message 5 of 6
(2,876 Views)

@natasftw wrote:

That was throwing me off too, especially considering 0x30-0x39 are the ASCII values for 0-9.  0x01-0x09 result in characters that can't be seen.  I wouldn't expect them to show up as recognizable numbers.


 If I understood correctly, he said that the string was set to hex display.

0 Kudos
Message 6 of 6
(2,863 Views)