Shop OBEX P1 Docs P2 Docs Learn Events
Is it possible to split a variable down by each digit? — Parallax Forums

Is it possible to split a variable down by each digit?

eagletalontimeagletalontim Posts: 1,399
edited 2008-07-06 19:37 in General Discussion
This is a new one for me. I am trying to display different digits on 2 separate 7 segment displays. I have gotten most of it to work, but for some reason, when I pass the digit to be displayed and try to chop it down to display on the right segment, it shows a 1 or a 0 instead of the number I pass.

Here is a rough example on what i am trying to do :
digit = WORD
fdigit = WORD
sdigit = WORD

digit = 93
fdigit = digit.0
sdigit = digit.1

the output should be :
fdigit = 9
sdigit = 3

For some reason, I can't get the right output. Thanks for your help in advance!

Comments

  • JonnyMacJonnyMac Posts: 9,392
    edited 2008-07-06 18:40
    If digit is limited to 99 then it's pretty easy:

    fdigit = digit / 10
    sdigit = __remainder

    You can now use these values to pull the appropriate segment maps from a table.

    The reason your code is not working is that the dot notation of a variable is for bits (0 or 1), not decimal digits. BTW, you can use bytes instead of words to conserve RAM space.
  • eagletalontimeagletalontim Posts: 1,399
    edited 2008-07-06 18:44
    I was looking into the _remainder command, but I need to be able to successfully pull each character from 0 to 59999. Is there any way to easily pull each character from the variable one at a time? I am used to php programming where you can do var[noparse][[/noparse]0], var and so on.
  • JonnyMacJonnyMac Posts: 9,392
    edited 2008-07-06 19:37
    You weren't specific in your first post and didn't attach your own code -- both these things will get you better answers faster. See attached; I wrote a quick function that can extract a digit from a variable (byte or word).

    [noparse][[/noparse]Edit] I modified the function to work around a divide by one bug in SX/B 1.51.03 and added a subroutine that will move the digits of a value to an array.

    Post Edited (JonnyMac) : 7/6/2008 9:52:40 PM GMT
Sign In or Register to comment.