Hi Fellipe,
If the ascii string content is numbers 0 to 9, then perhaps you can use
function string_to_ dword from strings.jal library.

However I'm not sure is better than yours. It depends of what you try to
hit: best structured source code, fastest hex code or lowest hw stack.
best wishes,

On Sat 21 Jan 2023, 8:57 PM flyway38 <[email protected] wrote:

> 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
> <https://groups.google.com/d/msgid/jallib/f3e04583-4ea7-4302-9273-220361de6874n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>

-- 
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/CAM%2Bj4qt2U1ZuL2Pii97SaD6G%3D3Om-uwbaXqw-YT%3DSNSW99eRZw%40mail.gmail.com.

Reply via email to