PDA

View Full Version : what happens when a variable gets to be 65535 + x



bartman
- 4th December 2004, 23:50
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

Melanie
- 5th December 2004, 10:02
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

bartman
- 5th December 2004, 15:59
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

Melanie
- 5th December 2004, 23:06
That is correct.