Hello to all,
Am facing this task of converting to a word var, for use in some
calculations, a value that is received as a ascii string, ex: "00800" that
need it as a value of 800 in a word var.
Came up with this code below, but need some advice on a more efficient
method to get same result.
Any ideas would be great.
function AsciiStringToWord(byte IN str[]) return word is
-- Max LEN in str is 5 chars (Converting to word: max= 65535)
var word wRtn
var word len = count(str)
var byte i
var byte ii
--
for len using i loop -- Can be use STEP -1 ??
--wRtn = wRtn + str[i]*(10^i) -- Can be used "^" for power operations
???
-- This code would be enough
-- Here my alternate code for same result
case i of
0: wRtn=wRtn+(str[5 - len + i]-48)
1: wRtn=wRtn+(str[5 - len + i]-48)*10
2: wRtn=wRtn+(str[5 - len + i]-48)*100
3: wRtn=wRtn+(str[5 - len + i]-48)*1_000
4: wRtn=wRtn+(str[5 - len + i]-48)*10_000
end case
end loop
end function
Thank you.
Kind regards,
Filipe Santos
--
You received this message because you are subscribed to the Google Groups
"jallib" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/jallib/f3e04583-4ea7-4302-9273-220361de6874n%40googlegroups.com.