This should be simple?


Closed Thread
Results 1 to 5 of 5

Hybrid View

  1. #1


    Did you find this post helpful? Yes | No

    Default

    IT WORKS! Now I'll spend the rest of the afternoon figuring out HOW it works! Thank you!
    Dave

  2. #2
    skimask's Avatar
    skimask Guest


    Did you find this post helpful? Yes | No

    Default

    Quote Originally Posted by jderson View Post
    IT WORKS! Now I'll spend the rest of the afternoon figuring out HOW it works! Thank you!
    Dave
    All the program is doing is pretending that two smaller variables are one bigger variable.
    If you think about it, you can extrapolate the concept out to as far as you've got memory for.
    A byte will hold 0-255, good enough for 0-99, not quite a 1000
    A word will hold 0-65535, good enough for a '3-digit group'.
    So a word holds a 3-digit group, just like a calculator does...
    You keep adding into the least significant 3-digit group, checking after each add if that '3-digit group' overflowed by going over 999. Going over 999 isn't overflowed for a word variable, but it's overflowed for a '3-digit group'. Therefore, since the variable has held the whole value, we can subtract out the maximum of that '3-digit group', in this case 1000, and add 1 (or 2 if you overflowed to 2000, or 3 if you overflowed to 3000, and so on) to the next higher '3-digit group', which in this case, would also be the next higher word variable.

    Example:
    Code:
    ones var word
    thousands var word
    millions var word
    billions var word
    trillions var word
    quadrillions var word
    quintillions var word
    sextillions var word
    
    lcdout $fe , 1
    'if you had a 40 character LCD, this would probably show up like it should
    main:
    lcdout dec3 sextillioins,dec3 quintillions,dec3 quadrillions,dec3 trillions,dec3 billions,_
       dec3 millions,dec3 thousands,dec3 ones
    
    ones = ones + 1
    
    if ones > 1000 then
     ones = ones - 1000 : thousands = thousands + 1
    end
    if thousands > 1000 then
     thousands = thousands - 1000 : millions = millions + 1
    endif
    if millions > 1000 then
     millions = million - 1000 : billions = billions + 1
    endif
    if billions > 1000 then
     billions = billions - 1000 : trillions = trillions + 1
    endif
    if trillions > 1000 then
     trillions = trillions - 1000 : quadrillions = quadrillions + 1
    endif
    if quadrillions > 1000 then
     quadrillions = quadrillions - 1000 : quintilliions = quintillions + 1
    endif
    if quintillions > 1000 then
     quintillions = quintillions - 1000 : sextillions = sextillions + 1
    endif
    if sextillions > 1000 then you've counted a helluva lot of numbers
    
    goto main
    end
    I wouldn't sit around waiting for the highest digit to roll over though... Might be there for awhile...

  3. #3


    Did you find this post helpful? Yes | No

    Default

    Most EXCELLENT! I have learned so much from you helpful people, thank you

Similar Threads

  1. Simple RF remote control code
    By Bruce in forum Code Examples
    Replies: 13
    Last Post: - 22nd January 2014, 11:45
  2. Simple Blinking LED - WTF!!
    By johnnylynx in forum mel PIC BASIC Pro
    Replies: 5
    Last Post: - 1st February 2010, 07:19
  3. Simple LCD code not working!...WHY?
    By jellis00 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 29th November 2009, 20:48
  4. Replies: 0
    Last Post: - 3rd February 2009, 00:23
  5. Replies: 4
    Last Post: - 7th September 2005, 15:11

Members who have read this thread : 0

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