what happens when a variable gets to be 65535 + x


Closed Thread
Results 1 to 4 of 4
  1. #1
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189

    Question what happens when a variable gets to be 65535 + x

    In this bit of code:

    <b>
    for X = 1 to 100
    number = number + 1001
    next X
    </b>

    Eventually the number will be higher than 65535 so what happens to the number? I assume some internal calculation is going to drop it back down to 0 + something and it will start again.

    How does the program/pic circuit handle this?

    As with my random number questions does this number automatically cycle through all possible numbers between 1 and 65535?

    Thanks.

    Bart

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


    Did you find this post helpful? Yes | No

    Default

    It just rolls thru zero and carries on.

    WORD variable Examples...

    65535+1=0
    65535+2=1
    65535+10=9

    and so forth...

    Same with BYTE variables...

    255+1=0
    255+2=1
    255+10=9

  3. #3
    Join Date
    Nov 2004
    Location
    Saskatchewan Canada
    Posts
    189


    Did you find this post helpful? Yes | No

    Default

    Thanks. I figured it might based on the byte questions I had, but wanted to make sure in case something ends up locking up later. I'm having that problem.

    On a related note. I assume any multiplication that creates a number beyond 65535 also rolls and any division that leaves a remainder the remainder is dropped and only the integer left?

    Bart

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


    Did you find this post helpful? Yes | No

    Default

    That is correct.

Similar Threads

  1. EEPROM Variables (EE_Vars.pbp)
    By Darrel Taylor in forum Code Examples
    Replies: 79
    Last Post: - 26th October 2012, 00:06
  2. Variable PWM PIC18F2431
    By trr1985 in forum mel PIC BASIC Pro
    Replies: 7
    Last Post: - 12th June 2009, 06:03
  3. Help with sound command in 2 programs
    By hyperboarder in forum mel PIC BASIC Pro
    Replies: 4
    Last Post: - 5th July 2007, 20:36
  4. WORD vs BYTE variable lengths
    By bartman in forum General
    Replies: 0
    Last Post: - 28th November 2005, 21:16
  5. Storing a variable in EEPROM
    By Tissy in forum mel PIC BASIC Pro
    Replies: 6
    Last Post: - 29th October 2005, 13:53

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