Determining variable length (number of digits) possible?


Results 1 to 15 of 15

Threaded View

  1. #2
    Join Date
    Nov 2005
    Location
    Bombay, India
    Posts
    966


    Did you find this post helpful? Yes | No

    Default Re: Determining variable length (number of digits) possible?

    I will give a generic answer as my PICBasic skills are weak at the moment

    Assume your variable x contains 1000

    You can strip out digits like this from Right to left with position 0 at the right (least significant position) of the display

    Code:
        position = 0
         if x > 9999 then x=9999                  ' restrict to maximum you can display
    
         while x != 0
             digit[position] = x Mod 10            ' keep the digit
             x = x div 10                                  ' integer divide by 10
             position = position+1                   ' next display position
         end while
    This will automatically stop if the value is 1..9 at 1 digit, or 11..99 at 2 digits and so on.
    Last edited by Jerson; - 8th December 2020 at 02:31. Reason: formatting

Similar Threads

  1. Replies: 11
    Last Post: - 9th March 2020, 12:37
  2. Measuring a variable freq/length pulse and generating more pulses.
    By retepsnikrep in forum mel PIC BASIC Pro
    Replies: 10
    Last Post: - 18th September 2014, 09:10
  3. Determining how much RAM is available?
    By Art in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 20th February 2012, 16:04
  4. Determining LONG compiler
    By Charles Linquis in forum mel PIC BASIC Pro
    Replies: 2
    Last Post: - 10th September 2011, 19:19
  5. HSERIN for variable length string
    By Pic2008 in forum mel PIC BASIC Pro
    Replies: 1
    Last Post: - 19th February 2010, 05:58

Members who have read this thread : 1

You do not have permission to view the list of names.

Posting Permissions

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