Split number into variables


+ Reply to Thread
Results 1 to 4 of 4
  1. #1
    psmeets's Avatar
    psmeets Guest

    Default Split number into variables

    Hi,

    I am working on a 3 digit counter and want to display a number, let's say '263'. This value is stored in a variable (word).

    To display the number correctly I need to split this number into three separate variables.

    e.g.
    2 into var1
    6 into var2
    3 into var3


    Can anybody help me with a piece of code of with a hint?

    Thanks!

    Patrick

  2. #2
    Join Date
    Jul 2003
    Posts
    2,358

    Default

    Here's the piece of example code...

    MyVar=263

    var1 = MyVar DIG 2 (var1 contains the 2)
    var2 = MyVar DIG 1 (var2 contains the 6)
    var3 = MyVar DIG 0 (var3 contains the 3)

    And as a bonus here's the hint - See PBP manual 4.17.7 use of DIG function.

    Melanie

  3. #3
    psmeets's Avatar
    psmeets Guest

    Default

    Hmmm Shame on me, RTFM!!

    Thanks anyways you helped me a lot!

    Patrick

  4. #4
    Desterline's Avatar
    Desterline Guest

    Default

    Thanks Melanie,
    I have a copy of the manual, and have read it repeatedly, but somehow missed this little nugget. Would have come in handy more than once in the past. Thanks for pointing it out.

    -Denny

Similar Threads

  1. Dynamic USB Serial Number (PIC18F4550)
    By awmt102 in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th July 2009, 17:03
  2. Working with the random number generator
    By kwelna in forum mel PIC BASIC
    Replies: 9
    Last Post: - 16th January 2007, 17:50
  3. Variables not appearing in Watch Window MPLabv7.3
    By jd76duke in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 16th June 2006, 14:36
  4. Random number results
    By bartman in forum mel PIC BASIC
    Replies: 3
    Last Post: - 9th March 2005, 17:39
  5. more random number questions
    By bartman in forum mel PIC BASIC
    Replies: 1
    Last Post: - 14th November 2004, 17:55

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts