Page 1 of 1
Convert a character to its numerical value
Posted: Fri Apr 16, 2021 3:01 pm
by alanwms
I notice that "stringtoint" does not allow operation of alpha chars. Only numeric chars. Do we have a method of doing that?
Re: Convert a character to its numerical value
Posted: Fri Apr 16, 2021 3:12 pm
by mnfisher
What are you trying to achieve?
For example 'A' do you want 10 (hex value) or 65 ASCII value?
Martin
Re: Convert a character to its numerical value
Posted: Mon Apr 19, 2021 2:44 am
by alanwms
Sure - I would like to stringtoint$("A") to have an outcome of 41 (I think that's the equate).
Currently I am achieving this with the function compare with "". That seems to give me an equivalency.
Wouldn't it be great to use stringtoint$ to get the equivalent decimal?
Re: Convert a character to its numerical value
Posted: Mon Apr 19, 2021 3:54 am
by mnfisher
If you want the ASCII value 'A' = 65 = 0x41
So for a string :
in a calculation block
Will get the value of the first character of the string
Or if you just want the value of a character
note the single quote ' instead of double quote "
You can use a character constant instead of a constant to make your code more readable
to check if c is a digit for example
Martin
Re: Convert a character to its numerical value
Posted: Wed Apr 21, 2021 1:43 pm
by alanwms
Martin - You are the man!
Thank you for that tid bit.